diff options
author | Takeshi Abe <tabe@fixedpoint.jp> | 2017-11-18 22:43:41 +0900 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2017-12-19 07:56:37 +0100 |
commit | 28e1f3c77fe19091cddf527f7758386dddcdad34 (patch) | |
tree | 5bed1e92de8b2ace3e70a3db4bac086409dff99d | |
parent | 67bd9382aa17594cb7a6d1fad304ed9f275941b1 (diff) |
svl: Fix possible memleak at deleting DdeService
Change-Id: Ie10d4199999c4331af29dee2a8d98132488caa6e
Reviewed-on: https://gerrit.libreoffice.org/44909
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
-rw-r--r-- | include/svl/svdde.hxx | 7 | ||||
-rw-r--r-- | svl/source/svdde/ddeimp.hxx | 2 | ||||
-rw-r--r-- | svl/source/svdde/ddesvr.cxx | 29 | ||||
-rw-r--r-- | svl/unx/source/svdde/ddedummy.cxx | 5 |
4 files changed, 19 insertions, 24 deletions
diff --git a/include/svl/svdde.hxx b/include/svl/svdde.hxx index 003a14f83923..2f07eb768117 100644 --- a/include/svl/svdde.hxx +++ b/include/svl/svdde.hxx @@ -48,7 +48,7 @@ struct Conversation; typedef ::std::vector< DdeService* > DdeServices; typedef ::std::vector< long > DdeFormats; -typedef ::std::vector< Conversation* > ConvList; +typedef std::vector<std::unique_ptr<Conversation>> ConvList; class SVL_DLLPUBLIC DdeData @@ -297,7 +297,7 @@ private: DdeFormats aFormats; DdeTopic* pSysTopic; DdeString* pName; - ConvList* pConv; + ConvList m_vConv; short nStatus; SVL_DLLPRIVATE bool HasCbFormat( sal_uInt16 ); @@ -306,6 +306,9 @@ public: DdeService( SAL_UNUSED_PARAMETER const OUString& ); virtual ~DdeService(); + DdeService( const DdeService& ) = delete; + DdeService& operator= ( const DdeService& ) = delete; + const OUString GetName() const; short GetError() { return nStatus; } diff --git a/svl/source/svdde/ddeimp.hxx b/svl/source/svdde/ddeimp.hxx index 22df0864002e..3e6cf02483b4 100644 --- a/svl/source/svdde/ddeimp.hxx +++ b/svl/source/svdde/ddeimp.hxx @@ -37,8 +37,6 @@ struct Conversation DdeTopic* pTopic; }; -typedef ::std::vector< Conversation* > ConvList; - class DdeInternal { diff --git a/svl/source/svdde/ddesvr.cxx b/svl/source/svdde/ddesvr.cxx index ce26573988b4..45098bec4764 100644 --- a/svl/source/svdde/ddesvr.cxx +++ b/svl/source/svdde/ddesvr.cxx @@ -153,7 +153,7 @@ HDDEDATA CALLBACK DdeInternal::SvrCallback( pC = new Conversation; pC->hConv = hConv; pC->pTopic = pTopic; - pService->pConv->push_back( pC ); + pService->m_vConv.emplace_back( pC ); } } return nullptr; @@ -162,9 +162,9 @@ HDDEDATA CALLBACK DdeInternal::SvrCallback( for (DdeServices::iterator aI = rAll.begin(); aI != rAll.end(); ++aI) { pService = *aI; - for ( size_t i = 0, n = pService->pConv->size(); i < n; ++i ) + for ( size_t i = 0, n = pService->m_vConv.size(); i < n; ++i ) { - pC = (*pService->pConv)[ i ]; + pC = pService->m_vConv[ i ].get(); if ( pC->hConv == hConv ) goto found; } @@ -176,14 +176,13 @@ found: if ( nCode == XTYP_DISCONNECT) { DisconnectTopic(*pC->pTopic, hConv); - for ( ConvList::iterator it = pService->pConv->begin(); - it != pService->pConv->end(); + for ( ConvList::iterator it = pService->m_vConv.begin(); + it != pService->m_vConv.end(); ++it ) { - if ( *it == pC ) + if ( it->get() == pC ) { - delete *it; - pService->pConv->erase( it ); + pService->m_vConv.erase( it ); break; } } @@ -435,8 +434,6 @@ DdeService::DdeService( const OUString& rService ) else nStatus = DMLERR_NO_ERROR; - pConv = new ConvList; - if ( pInst->pServicesSvr ) pInst->pServicesSvr->push_back( this ); @@ -482,7 +479,6 @@ DdeService::~DdeService() ImpDeinitInstData(); } } - delete pConv; } const OUString DdeService::GetName() const @@ -513,16 +509,11 @@ void DdeService::RemoveTopic( const DdeTopic& rTopic ) aTopics.erase(iter); // Delete all conversions! // Or else we work on deleted topics! - for( size_t n = pConv->size(); n; ) + for( size_t n = m_vConv.size(); n; ) { - Conversation* pC = (*pConv)[ --n ]; + auto const& pC = m_vConv[ --n ]; if( pC->pTopic == &rTopic ) - { - ConvList::iterator it = pConv->begin(); - ::std::advance( it, n ); - delete *it; - pConv->erase( it ); - } + m_vConv.erase( m_vConv.begin() + n ); } break; } diff --git a/svl/unx/source/svdde/ddedummy.cxx b/svl/unx/source/svdde/ddedummy.cxx index 856d79dc5db2..e934b865a857 100644 --- a/svl/unx/source/svdde/ddedummy.cxx +++ b/svl/unx/source/svdde/ddedummy.cxx @@ -20,6 +20,10 @@ #include <svl/svdde.hxx> #include <rtl/instance.hxx> +struct Conversation +{ +}; + struct DdeDataImp { }; @@ -202,7 +206,6 @@ const OUString DdeTopic::GetName() const DdeService::DdeService( const OUString& ) : pSysTopic(nullptr) , pName(nullptr) - , pConv(nullptr) , nStatus(0) { } |