Kaydet (Commit) 28e1f3c7 authored tarafından Takeshi Abe's avatar Takeshi Abe Kaydeden (comit) Noel Grandin

svl: Fix possible memleak at deleting DdeService

Change-Id: Ie10d4199999c4331af29dee2a8d98132488caa6e
Reviewed-on: https://gerrit.libreoffice.org/44909Tested-by: 's avatarJenkins <ci@libreoffice.org>
Reviewed-by: 's avatarNoel Grandin <noel.grandin@collabora.co.uk>
üst 67bd9382
...@@ -48,7 +48,7 @@ struct Conversation; ...@@ -48,7 +48,7 @@ struct Conversation;
typedef ::std::vector< DdeService* > DdeServices; typedef ::std::vector< DdeService* > DdeServices;
typedef ::std::vector< long > DdeFormats; typedef ::std::vector< long > DdeFormats;
typedef ::std::vector< Conversation* > ConvList; typedef std::vector<std::unique_ptr<Conversation>> ConvList;
class SVL_DLLPUBLIC DdeData class SVL_DLLPUBLIC DdeData
...@@ -297,7 +297,7 @@ private: ...@@ -297,7 +297,7 @@ private:
DdeFormats aFormats; DdeFormats aFormats;
DdeTopic* pSysTopic; DdeTopic* pSysTopic;
DdeString* pName; DdeString* pName;
ConvList* pConv; ConvList m_vConv;
short nStatus; short nStatus;
SVL_DLLPRIVATE bool HasCbFormat( sal_uInt16 ); SVL_DLLPRIVATE bool HasCbFormat( sal_uInt16 );
...@@ -306,6 +306,9 @@ public: ...@@ -306,6 +306,9 @@ public:
DdeService( SAL_UNUSED_PARAMETER const OUString& ); DdeService( SAL_UNUSED_PARAMETER const OUString& );
virtual ~DdeService(); virtual ~DdeService();
DdeService( const DdeService& ) = delete;
DdeService& operator= ( const DdeService& ) = delete;
const OUString GetName() const; const OUString GetName() const;
short GetError() { return nStatus; } short GetError() { return nStatus; }
......
...@@ -37,8 +37,6 @@ struct Conversation ...@@ -37,8 +37,6 @@ struct Conversation
DdeTopic* pTopic; DdeTopic* pTopic;
}; };
typedef ::std::vector< Conversation* > ConvList;
class DdeInternal class DdeInternal
{ {
......
...@@ -153,7 +153,7 @@ HDDEDATA CALLBACK DdeInternal::SvrCallback( ...@@ -153,7 +153,7 @@ HDDEDATA CALLBACK DdeInternal::SvrCallback(
pC = new Conversation; pC = new Conversation;
pC->hConv = hConv; pC->hConv = hConv;
pC->pTopic = pTopic; pC->pTopic = pTopic;
pService->pConv->push_back( pC ); pService->m_vConv.emplace_back( pC );
} }
} }
return nullptr; return nullptr;
...@@ -162,9 +162,9 @@ HDDEDATA CALLBACK DdeInternal::SvrCallback( ...@@ -162,9 +162,9 @@ HDDEDATA CALLBACK DdeInternal::SvrCallback(
for (DdeServices::iterator aI = rAll.begin(); aI != rAll.end(); ++aI) for (DdeServices::iterator aI = rAll.begin(); aI != rAll.end(); ++aI)
{ {
pService = *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 ) if ( pC->hConv == hConv )
goto found; goto found;
} }
...@@ -176,14 +176,13 @@ found: ...@@ -176,14 +176,13 @@ found:
if ( nCode == XTYP_DISCONNECT) if ( nCode == XTYP_DISCONNECT)
{ {
DisconnectTopic(*pC->pTopic, hConv); DisconnectTopic(*pC->pTopic, hConv);
for ( ConvList::iterator it = pService->pConv->begin(); for ( ConvList::iterator it = pService->m_vConv.begin();
it != pService->pConv->end(); it != pService->m_vConv.end();
++it ++it
) { ) {
if ( *it == pC ) if ( it->get() == pC )
{ {
delete *it; pService->m_vConv.erase( it );
pService->pConv->erase( it );
break; break;
} }
} }
...@@ -435,8 +434,6 @@ DdeService::DdeService( const OUString& rService ) ...@@ -435,8 +434,6 @@ DdeService::DdeService( const OUString& rService )
else else
nStatus = DMLERR_NO_ERROR; nStatus = DMLERR_NO_ERROR;
pConv = new ConvList;
if ( pInst->pServicesSvr ) if ( pInst->pServicesSvr )
pInst->pServicesSvr->push_back( this ); pInst->pServicesSvr->push_back( this );
...@@ -482,7 +479,6 @@ DdeService::~DdeService() ...@@ -482,7 +479,6 @@ DdeService::~DdeService()
ImpDeinitInstData(); ImpDeinitInstData();
} }
} }
delete pConv;
} }
const OUString DdeService::GetName() const const OUString DdeService::GetName() const
...@@ -513,16 +509,11 @@ void DdeService::RemoveTopic( const DdeTopic& rTopic ) ...@@ -513,16 +509,11 @@ void DdeService::RemoveTopic( const DdeTopic& rTopic )
aTopics.erase(iter); aTopics.erase(iter);
// Delete all conversions! // Delete all conversions!
// Or else we work on deleted topics! // 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 ) if( pC->pTopic == &rTopic )
{ m_vConv.erase( m_vConv.begin() + n );
ConvList::iterator it = pConv->begin();
::std::advance( it, n );
delete *it;
pConv->erase( it );
}
} }
break; break;
} }
......
...@@ -20,6 +20,10 @@ ...@@ -20,6 +20,10 @@
#include <svl/svdde.hxx> #include <svl/svdde.hxx>
#include <rtl/instance.hxx> #include <rtl/instance.hxx>
struct Conversation
{
};
struct DdeDataImp struct DdeDataImp
{ {
}; };
...@@ -202,7 +206,6 @@ const OUString DdeTopic::GetName() const ...@@ -202,7 +206,6 @@ const OUString DdeTopic::GetName() const
DdeService::DdeService( const OUString& ) DdeService::DdeService( const OUString& )
: pSysTopic(nullptr) : pSysTopic(nullptr)
, pName(nullptr) , pName(nullptr)
, pConv(nullptr)
, nStatus(0) , nStatus(0)
{ {
} }
......
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