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