diff options
author | Takeshi Abe <tabe@fixedpoint.jp> | 2016-03-21 08:16:42 +0900 |
---|---|---|
committer | Michael Stahl <mstahl@redhat.com> | 2016-03-22 13:42:07 +0000 |
commit | e3428225160923ecbc36e44a94389d8f44ab225d (patch) | |
tree | bbc4fb31281242ccb9d087618c6a39e2f68956a0 | |
parent | 998be2816fd74cf8894b675d04f9cf9773c72da6 (diff) |
sfx2: Fix memleak
i.e. free pMedium when CheckPasswd_Impl() returns ERRCODE_ABORT.
Change-Id: I452074e5189afe64016226c1a193a68f40e9c43d
Reviewed-on: https://gerrit.libreoffice.org/23387
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Michael Stahl <mstahl@redhat.com>
-rw-r--r-- | sfx2/source/doc/docinsert.cxx | 15 |
1 files changed, 8 insertions, 7 deletions
diff --git a/sfx2/source/doc/docinsert.cxx b/sfx2/source/doc/docinsert.cxx index 56a84ee6766f..b4b3d74c5eda 100644 --- a/sfx2/source/doc/docinsert.cxx +++ b/sfx2/source/doc/docinsert.cxx @@ -39,6 +39,7 @@ #include <svl/eitem.hxx> #include <svl/intitem.hxx> #include <svl/stritem.hxx> +#include <memory> using namespace ::com::sun::star; using namespace ::com::sun::star::lang; @@ -80,14 +81,14 @@ void DocumentInserter::StartExecuteModal( const Link<sfx2::FileDialogHelper*,voi SfxMedium* DocumentInserter::CreateMedium() { - SfxMedium* pMedium = nullptr; + std::unique_ptr<SfxMedium> pMedium; if (!m_nError && m_pItemSet && !m_pURLList.empty()) { DBG_ASSERT( m_pURLList.size() == 1, "DocumentInserter::CreateMedium(): invalid URL list count" ); OUString sURL(m_pURLList[0]); - pMedium = new SfxMedium( + pMedium.reset(new SfxMedium( sURL, SFX_STREAM_READONLY, - SfxGetpApp()->GetFilterMatcher().GetFilter4FilterName( m_sFilter ), m_pItemSet ); + SfxGetpApp()->GetFilterMatcher().GetFilter4FilterName( m_sFilter ), m_pItemSet )); pMedium->UseInteractionHandler( true ); SfxFilterMatcher* pMatcher = nullptr; if ( !m_sDocFactory.isEmpty() ) @@ -100,15 +101,15 @@ SfxMedium* DocumentInserter::CreateMedium() if ( nError == ERRCODE_NONE && pFilter ) pMedium->SetFilter( pFilter ); else - DELETEZ( pMedium ); + pMedium.reset(); - if ( pMedium && CheckPasswd_Impl( nullptr, SfxGetpApp()->GetPool(), pMedium ) == ERRCODE_ABORT ) - pMedium = nullptr; + if ( pMedium && CheckPasswd_Impl( nullptr, SfxGetpApp()->GetPool(), pMedium.get() ) == ERRCODE_ABORT ) + pMedium.reset(); DELETEZ( pMatcher ); } - return pMedium; + return pMedium.release(); } SfxMediumList* DocumentInserter::CreateMediumList() |