Kaydet (Commit) 32074859 authored tarafından Noel Grandin's avatar Noel Grandin

loplugin:useuniqueptr in SwDocShell::StartConvertFrom

fixing a leak in SwView::InsertMedium

Change-Id: I9abd97151b0fd7b3f6c286926e1a317ea47dc232
Reviewed-on: https://gerrit.libreoffice.org/60606
Tested-by: Jenkins
Reviewed-by: 's avatarNoel Grandin <noel.grandin@collabora.co.uk>
üst ce30c631
......@@ -231,7 +231,7 @@ public:
{ return const_cast<SwDocShell*>(this)->GetFEShell(); }
/// For inserting document.
Reader* StartConvertFrom(SfxMedium& rMedium, SwReader** ppRdr,
Reader* StartConvertFrom(SfxMedium& rMedium, std::unique_ptr<SwReader>& rpRdr,
SwCursorShell const * pCursorSh = nullptr, SwPaM* pPaM = nullptr);
#if defined(_WIN32)
......
......@@ -1061,12 +1061,12 @@ void InsertFile(SwUnoCursor* pUnoCursor, const OUString& rURL,
pMed->Download(); // if necessary: start the download
if( aRef.is() && 1 < aRef->GetRefCount() ) // Ref still valid?
{
SwReader* pRdr;
std::unique_ptr<SwReader> pRdr;
SfxItemSet* pSet = pMed->GetItemSet();
pSet->Put(SfxBoolItem(FN_API_CALL, true));
if(!sPassword.isEmpty())
pSet->Put(SfxStringItem(SID_PASSWORD, sPassword));
Reader *pRead = pDocSh->StartConvertFrom( *pMed, &pRdr, nullptr, pUnoCursor);
Reader *pRead = pDocSh->StartConvertFrom( *pMed, pRdr, nullptr, pUnoCursor);
if( pRead )
{
......@@ -1091,9 +1091,6 @@ void InsertFile(SwUnoCursor* pUnoCursor, const OUString& rURL,
nContent = 0;
pUnoCursor->GetMark()->nContent.Assign( pCntNode, nContent );
}
delete pRdr;
}
}
}
......
......@@ -153,17 +153,16 @@ bool SwDocShell::InsertGeneratedStream(SfxMedium & rMedium,
if (!::sw::XTextRangeToSwPaM(aPam, xInsertPosition))
return false;
// similar to SwView::InsertMedium
SwReader *pReader(nullptr);
Reader *const pRead = StartConvertFrom(rMedium, &pReader, nullptr, &aPam);
std::unique_ptr<SwReader> pReader;
Reader *const pRead = StartConvertFrom(rMedium, pReader, nullptr, &aPam);
if (!pRead)
return false;
ErrCode const nError = pReader->Read(*pRead);
delete pReader;
return ERRCODE_NONE == nError;
}
// Prepare loading
Reader* SwDocShell::StartConvertFrom(SfxMedium& rMedium, SwReader** ppRdr,
Reader* SwDocShell::StartConvertFrom(SfxMedium& rMedium, std::unique_ptr<SwReader>& rpRdr,
SwCursorShell const *pCursorShell,
SwPaM* pPaM )
{
......@@ -195,10 +194,12 @@ Reader* SwDocShell::StartConvertFrom(SfxMedium& rMedium, SwReader** ppRdr,
? SwReaderType::Storage & pRead->GetReaderType()
: SwReaderType::Stream & pRead->GetReaderType() )
{
*ppRdr = pPaM ? new SwReader( rMedium, aFileName, *pPaM ) :
pCursorShell ?
new SwReader( rMedium, aFileName, *pCursorShell->GetCursor() )
: new SwReader( rMedium, aFileName, m_xDoc.get() );
if (pPaM)
rpRdr.reset(new SwReader( rMedium, aFileName, *pPaM ));
else if (pCursorShell)
rpRdr.reset(new SwReader( rMedium, aFileName, *pCursorShell->GetCursor() ));
else
rpRdr.reset(new SwReader( rMedium, aFileName, m_xDoc.get() ));
}
else
return nullptr;
......@@ -230,8 +231,8 @@ Reader* SwDocShell::StartConvertFrom(SfxMedium& rMedium, SwReader** ppRdr,
// Loading
bool SwDocShell::ConvertFrom( SfxMedium& rMedium )
{
SwReader* pRdr;
SwRead pRead = StartConvertFrom(rMedium, &pRdr);
std::unique_ptr<SwReader> pRdr;
SwRead pRead = StartConvertFrom(rMedium, pRdr);
if (!pRead)
return false; // #129881# return if no reader is found
tools::SvRef<SotStorage> pStg=pRead->getSotStorageRef(); // #i45333# save sot storage ref in case of recursive calls
......@@ -278,7 +279,7 @@ bool SwDocShell::ConvertFrom( SfxMedium& rMedium )
UpdateFontList();
InitDrawModelAndDocShell(this, m_xDoc ? m_xDoc->getIDocumentDrawModelAccess().GetDrawModel() : nullptr);
delete pRdr;
pRdr.reset();
SW_MOD()->SetEmbeddedLoadSave( false );
......
......@@ -2155,8 +2155,8 @@ long SwView::InsertMedium( sal_uInt16 nSlotId, std::unique_ptr<SfxMedium> pMediu
pMedium->Download(); // start download if needed
if( aRef.is() && 1 < aRef->GetRefCount() ) // still a valid ref?
{
SwReader* pRdr;
Reader *pRead = pDocSh->StartConvertFrom(*pMedium, &pRdr, m_pWrtShell.get());
std::unique_ptr<SwReader> pRdr;
Reader *pRead = pDocSh->StartConvertFrom(*pMedium, pRdr, m_pWrtShell.get());
if( pRead ||
(pMedium->GetFilter()->GetFilterFlags() & SfxFilterFlags::STARONEFILTER) )
{
......@@ -2174,7 +2174,7 @@ long SwView::InsertMedium( sal_uInt16 nSlotId, std::unique_ptr<SfxMedium> pMediu
if( pRead )
{
nErrno = pRdr->Read( *pRead ); // and insert document
delete pRdr;
pRdr.reset();
}
else
{
......
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