Kaydet (Commit) f339cd61 authored tarafından Caolán McNamara's avatar Caolán McNamara

coverity#1340229 try and silence Resource leak

Change-Id: I5babf6365c50b7c5ad58cdb74729b9a8ac1c4ebc
üst 3c100a9c
...@@ -1534,13 +1534,13 @@ int SwFindDocShell( SfxObjectShellRef& xDocSh, ...@@ -1534,13 +1534,13 @@ int SwFindDocShell( SfxObjectShellRef& xDocSh,
} }
// 2. Open the file ourselves // 2. Open the file ourselves
SfxMedium* pMed = new SfxMedium( aTmpObj.GetMainURL( std::unique_ptr<SfxMedium> xMed(new SfxMedium( aTmpObj.GetMainURL(
INetURLObject::NO_DECODE ), StreamMode::READ ); INetURLObject::NO_DECODE ), StreamMode::READ ));
if( INetProtocol::File == aTmpObj.GetProtocol() ) if( INetProtocol::File == aTmpObj.GetProtocol() )
pMed->Download(); // Touch the medium (download it) xMed->Download(); // Touch the medium (download it)
const SfxFilter* pSfxFlt = nullptr; const SfxFilter* pSfxFlt = nullptr;
if( !pMed->GetError() ) if (!xMed->GetError())
{ {
SfxFilterMatcher aMatcher( OUString::createFromAscii(SwDocShell::Factory().GetShortName()) ); SfxFilterMatcher aMatcher( OUString::createFromAscii(SwDocShell::Factory().GetShortName()) );
...@@ -1551,24 +1551,24 @@ int SwFindDocShell( SfxObjectShellRef& xDocSh, ...@@ -1551,24 +1551,24 @@ int SwFindDocShell( SfxObjectShellRef& xDocSh,
} }
if( nVersion ) if( nVersion )
pMed->GetItemSet()->Put( SfxInt16Item( SID_VERSION, nVersion )); xMed->GetItemSet()->Put( SfxInt16Item( SID_VERSION, nVersion ));
if( !rPasswd.isEmpty() ) if( !rPasswd.isEmpty() )
pMed->GetItemSet()->Put( SfxStringItem( SID_PASSWORD, rPasswd )); xMed->GetItemSet()->Put( SfxStringItem( SID_PASSWORD, rPasswd ));
if( !pSfxFlt ) if( !pSfxFlt )
aMatcher.DetectFilter( *pMed, &pSfxFlt, false ); aMatcher.DetectFilter( *xMed, &pSfxFlt, false );
if( pSfxFlt ) if( pSfxFlt )
{ {
// We cannot do anything without a Filter // 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 // 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)); SwDocShell *const pNew(new SwDocShell(SfxObjectCreateMode::INTERNAL));
xLockRef = pNew; xLockRef = pNew;
xDocSh = static_cast<SfxObjectShell*>(xLockRef); xDocSh = static_cast<SfxObjectShell*>(xLockRef);
if( xDocSh->DoLoad( pMed ) ) if (xDocSh->DoLoad(xMed.release()))
{ {
SwDoc const& rDoc(*pNew->GetDoc()); SwDoc const& rDoc(*pNew->GetDoc());
const_cast<SwDoc&>(rDoc).GetNodes().ForEach(&lcl_MergePortions); const_cast<SwDoc&>(rDoc).GetNodes().ForEach(&lcl_MergePortions);
...@@ -1577,9 +1577,6 @@ int SwFindDocShell( SfxObjectShellRef& xDocSh, ...@@ -1577,9 +1577,6 @@ int SwFindDocShell( SfxObjectShellRef& xDocSh,
} }
} }
if( !xDocSh.Is() ) // Medium still needs to be deleted
delete pMed;
return 0; return 0;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment