summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNoel Grandin <noel.grandin@collabora.co.uk>2018-12-18 14:17:11 +0200
committerNoel Grandin <noel.grandin@collabora.co.uk>2018-12-18 15:30:16 +0100
commitfb19a399fef73c05bbe570cb32d43ccf28d1b9c6 (patch)
tree0b8d52e9bd81d04df835a9c7633fb159f75f1bb4
parent6f8186138d560d1949f89f4a525c0bd911af203e (diff)
use unique_ptr in SfxMediumList
fixing leak in SwGlobalTree::DialogClosedHdl Change-Id: I4a8e883bfe62181d4e332b3a0bbb85bbb332f711 Reviewed-on: https://gerrit.libreoffice.org/65333 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
-rw-r--r--include/sfx2/docinsert.hxx4
-rw-r--r--sfx2/source/doc/docinsert.cxx18
-rw-r--r--sw/source/uibase/utlui/glbltree.cxx9
3 files changed, 14 insertions, 17 deletions
diff --git a/include/sfx2/docinsert.hxx b/include/sfx2/docinsert.hxx
index 21fb1a2a9c37..d7712fb4324e 100644
--- a/include/sfx2/docinsert.hxx
+++ b/include/sfx2/docinsert.hxx
@@ -33,7 +33,7 @@ namespace weld { class Window; }
class SfxItemSet;
enum class FileDialogFlags;
-typedef ::std::vector< SfxMedium* > SfxMediumList;
+typedef ::std::vector< std::unique_ptr<SfxMedium> > SfxMediumList;
namespace sfx2 {
@@ -67,7 +67,7 @@ public:
void StartExecuteModal( const Link<sfx2::FileDialogHelper*,void>& _rDialogClosedLink );
std::unique_ptr<SfxMedium> CreateMedium(char const* pFallbackHack = nullptr);
- SfxMediumList* CreateMediumList();
+ SfxMediumList CreateMediumList();
};
} // namespace sfx2
diff --git a/sfx2/source/doc/docinsert.cxx b/sfx2/source/doc/docinsert.cxx
index d919f317123b..7b64851e0071 100644
--- a/sfx2/source/doc/docinsert.cxx
+++ b/sfx2/source/doc/docinsert.cxx
@@ -136,16 +136,16 @@ std::unique_ptr<SfxMedium> DocumentInserter::CreateMedium(char const*const pFall
return pMedium;
}
-SfxMediumList* DocumentInserter::CreateMediumList()
+SfxMediumList DocumentInserter::CreateMediumList()
{
- SfxMediumList* pMediumList = new SfxMediumList;
+ SfxMediumList aMediumList;
if (!m_nError && m_pItemSet && !m_pURLList.empty())
{
for (auto const& url : m_pURLList)
{
- SfxMedium* pMedium = new SfxMedium(
+ std::unique_ptr<SfxMedium> pMedium(new SfxMedium(
url, SFX_STREAM_READONLY,
- SfxGetpApp()->GetFilterMatcher().GetFilter4FilterName( m_sFilter ), std::unique_ptr<SfxItemSet>(m_pItemSet) );
+ SfxGetpApp()->GetFilterMatcher().GetFilter4FilterName( m_sFilter ), std::unique_ptr<SfxItemSet>(m_pItemSet) ));
pMedium->UseInteractionHandler( true );
@@ -155,16 +155,14 @@ SfxMediumList* DocumentInserter::CreateMediumList()
if ( nError == ERRCODE_NONE && pFilter )
pMedium->SetFilter( pFilter );
else
- DELETEZ( pMedium );
+ pMedium.reset();
- if( pMedium && CheckPasswd_Impl( nullptr, pMedium ) != ERRCODE_ABORT )
- pMediumList->push_back( pMedium );
- else
- delete pMedium;
+ if( pMedium && CheckPasswd_Impl( nullptr, pMedium.get() ) != ERRCODE_ABORT )
+ aMediumList.push_back( std::move(pMedium) );
}
}
- return pMediumList;
+ return aMediumList;
}
static void impl_FillURLList( sfx2::FileDialogHelper const * _pFileDlg, std::vector<OUString>& _rpURLList )
diff --git a/sw/source/uibase/utlui/glbltree.cxx b/sw/source/uibase/utlui/glbltree.cxx
index 28709b329ae2..575d89b2b85e 100644
--- a/sw/source/uibase/utlui/glbltree.cxx
+++ b/sw/source/uibase/utlui/glbltree.cxx
@@ -1356,13 +1356,13 @@ IMPL_LINK( SwGlobalTree, DialogClosedHdl, sfx2::FileDialogHelper*, _pFileDlg, vo
if ( ERRCODE_NONE != _pFileDlg->GetError() )
return;
- std::unique_ptr<SfxMediumList> pMedList(m_pDocInserter->CreateMediumList());
- if ( pMedList )
+ SfxMediumList aMedList(m_pDocInserter->CreateMediumList());
+ if ( !aMedList.empty() )
{
- Sequence< OUString >aFileNames( pMedList->size() );
+ Sequence< OUString >aFileNames( aMedList.size() );
OUString* pFileNames = aFileNames.getArray();
sal_Int32 nPos = 0;
- for (SfxMedium* pMed : *pMedList)
+ for (std::unique_ptr<SfxMedium>& pMed : aMedList)
{
OUString sFileName = pMed->GetURLObject().GetMainURL( INetURLObject::DecodeMechanism::NONE )
+ OUStringLiteral1(sfx2::cTokenSeparator)
@@ -1370,7 +1370,6 @@ IMPL_LINK( SwGlobalTree, DialogClosedHdl, sfx2::FileDialogHelper*, _pFileDlg, vo
+ OUStringLiteral1(sfx2::cTokenSeparator);
pFileNames[nPos++] = sFileName;
}
- pMedList.reset();
InsertRegion( m_pDocContent.get(), aFileNames );
m_pDocContent.reset();
}