diff options
author | Caolán McNamara <caolanm@redhat.com> | 2015-11-25 15:22:58 +0000 |
---|---|---|
committer | Caolán McNamara <caolanm@redhat.com> | 2015-11-25 15:45:59 +0000 |
commit | f339cd61186844d285b79d2e3cfb8da9e613ce49 (patch) | |
tree | ae88c129d329dad594f946ac0b99459bc3d7de1f | |
parent | 3c100a9c61ac984983d077e294c32b388d70d892 (diff) |
coverity#1340229 try and silence Resource leak
Change-Id: I5babf6365c50b7c5ad58cdb74729b9a8ac1c4ebc
-rw-r--r-- | sw/source/uibase/app/docsh2.cxx | 21 |
1 files changed, 9 insertions, 12 deletions
diff --git a/sw/source/uibase/app/docsh2.cxx b/sw/source/uibase/app/docsh2.cxx index 6897ac4a7f71..811deb4b029d 100644 --- a/sw/source/uibase/app/docsh2.cxx +++ b/sw/source/uibase/app/docsh2.cxx @@ -1534,13 +1534,13 @@ int SwFindDocShell( SfxObjectShellRef& xDocSh, } // 2. Open the file ourselves - SfxMedium* pMed = new SfxMedium( aTmpObj.GetMainURL( - INetURLObject::NO_DECODE ), StreamMode::READ ); + std::unique_ptr<SfxMedium> xMed(new SfxMedium( aTmpObj.GetMainURL( + INetURLObject::NO_DECODE ), StreamMode::READ )); if( INetProtocol::File == aTmpObj.GetProtocol() ) - pMed->Download(); // Touch the medium (download it) + xMed->Download(); // Touch the medium (download it) const SfxFilter* pSfxFlt = nullptr; - if( !pMed->GetError() ) + if (!xMed->GetError()) { SfxFilterMatcher aMatcher( OUString::createFromAscii(SwDocShell::Factory().GetShortName()) ); @@ -1551,24 +1551,24 @@ int SwFindDocShell( SfxObjectShellRef& xDocSh, } if( nVersion ) - pMed->GetItemSet()->Put( SfxInt16Item( SID_VERSION, nVersion )); + xMed->GetItemSet()->Put( SfxInt16Item( SID_VERSION, nVersion )); if( !rPasswd.isEmpty() ) - pMed->GetItemSet()->Put( SfxStringItem( SID_PASSWORD, rPasswd )); + xMed->GetItemSet()->Put( SfxStringItem( SID_PASSWORD, rPasswd )); if( !pSfxFlt ) - aMatcher.DetectFilter( *pMed, &pSfxFlt, false ); + aMatcher.DetectFilter( *xMed, &pSfxFlt, false ); if( pSfxFlt ) { // We cannot do anything without a Filter - pMed->SetFilter( pSfxFlt ); + xMed->SetFilter( pSfxFlt ); // If the new shell is created, SfxObjectShellLock should be used to let it be closed later for sure SwDocShell *const pNew(new SwDocShell(SfxObjectCreateMode::INTERNAL)); xLockRef = pNew; xDocSh = static_cast<SfxObjectShell*>(xLockRef); - if( xDocSh->DoLoad( pMed ) ) + if (xDocSh->DoLoad(xMed.release())) { SwDoc const& rDoc(*pNew->GetDoc()); const_cast<SwDoc&>(rDoc).GetNodes().ForEach(&lcl_MergePortions); @@ -1577,9 +1577,6 @@ int SwFindDocShell( SfxObjectShellRef& xDocSh, } } - if( !xDocSh.Is() ) // Medium still needs to be deleted - delete pMed; - return 0; } |