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,
}
// 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;
}
......
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