diff options
author | Noel Grandin <noel.grandin@collabora.co.uk> | 2018-09-14 14:38:42 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2018-09-18 09:06:13 +0200 |
commit | 32074859ba79489f1211542aca295a450443203e (patch) | |
tree | de24fda72eb88160624711ff14853143d981ce3f | |
parent | ce30c6316f7c7ffc727b2d852b6b42c8fefa52bd (diff) |
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: Noel Grandin <noel.grandin@collabora.co.uk>
-rw-r--r-- | sw/inc/docsh.hxx | 2 | ||||
-rw-r--r-- | sw/source/core/unocore/unocrsrhelper.cxx | 7 | ||||
-rw-r--r-- | sw/source/uibase/app/docsh.cxx | 23 | ||||
-rw-r--r-- | sw/source/uibase/uiview/view2.cxx | 6 |
4 files changed, 18 insertions, 20 deletions
diff --git a/sw/inc/docsh.hxx b/sw/inc/docsh.hxx index f2c17c1747c1..21344ca76cf7 100644 --- a/sw/inc/docsh.hxx +++ b/sw/inc/docsh.hxx @@ -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) diff --git a/sw/source/core/unocore/unocrsrhelper.cxx b/sw/source/core/unocore/unocrsrhelper.cxx index af5322b35d58..5e4d9d3af9fc 100644 --- a/sw/source/core/unocore/unocrsrhelper.cxx +++ b/sw/source/core/unocore/unocrsrhelper.cxx @@ -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; - } } } diff --git a/sw/source/uibase/app/docsh.cxx b/sw/source/uibase/app/docsh.cxx index ee1fa8228b4d..fd10b466dd54 100644 --- a/sw/source/uibase/app/docsh.cxx +++ b/sw/source/uibase/app/docsh.cxx @@ -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 ); diff --git a/sw/source/uibase/uiview/view2.cxx b/sw/source/uibase/uiview/view2.cxx index 06e3e8cc6bf0..a5a4ec0d730e 100644 --- a/sw/source/uibase/uiview/view2.cxx +++ b/sw/source/uibase/uiview/view2.cxx @@ -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 { |