From deea1b53447e5c32474369830be3f37db03aa5db Mon Sep 17 00:00:00 2001 From: csoler Date: Tue, 31 Jan 2017 20:59:50 +0100 Subject: [PATCH] moved temporary GXS object structures into rsgxsutil.h and used them in p3gxscircles to remove a memory leak --- libretroshare/src/gxs/rsgxsnetservice.cc | 39 ------------- libretroshare/src/gxs/rsgxsutil.h | 64 ++++++++++++++++++++++ libretroshare/src/services/p3gxscircles.cc | 2 +- 3 files changed, 65 insertions(+), 40 deletions(-) diff --git a/libretroshare/src/gxs/rsgxsnetservice.cc b/libretroshare/src/gxs/rsgxsnetservice.cc index a41229a2f..49fa13cb6 100644 --- a/libretroshare/src/gxs/rsgxsnetservice.cc +++ b/libretroshare/src/gxs/rsgxsnetservice.cc @@ -457,45 +457,6 @@ void RsGxsNetService::cleanRejectedMessages() ++it ; } -// temporary holds a map of pointers to class T, and destroys all pointers on delete. - -template -class RsGxsMetaDataTemporaryMap: public std::map -{ -public: - virtual ~RsGxsMetaDataTemporaryMap() - { - clear() ; - } - - virtual void clear() - { - for(typename RsGxsMetaDataTemporaryMap::iterator it = this->begin();it!=this->end();++it) - if(it->second != NULL) - delete it->second ; - - std::map::clear() ; - } -}; - -template -class RsGxsMetaDataTemporaryMapVector: public std::vector -{ -public: - virtual ~RsGxsMetaDataTemporaryMapVector() - { - clear() ; - } - - virtual void clear() - { - for(typename RsGxsMetaDataTemporaryMapVector::iterator it = this->begin();it!=this->end();++it) - if(it->second != NULL) - delete it->second ; - std::vector::clear() ; - } -}; - RsGxsGroupId RsGxsNetService::hashGrpId(const RsGxsGroupId& gid,const RsPeerId& pid) { static const uint32_t SIZE = RsGxsGroupId::SIZE_IN_BYTES + RsPeerId::SIZE_IN_BYTES ; diff --git a/libretroshare/src/gxs/rsgxsutil.h b/libretroshare/src/gxs/rsgxsutil.h index cfd777c90..fdcc96246 100644 --- a/libretroshare/src/gxs/rsgxsutil.h +++ b/libretroshare/src/gxs/rsgxsutil.h @@ -49,6 +49,70 @@ void freeAndClearContainerResource(Container container) container.clear(); } +// temporary holds a map of pointers to class T, and destroys all pointers on delete. + +template +class RsGxsMetaDataTemporaryMap: public std::map +{ +public: + virtual ~RsGxsMetaDataTemporaryMap() + { + clear() ; + } + + virtual void clear() + { + for(typename RsGxsMetaDataTemporaryMap::iterator it = this->begin();it!=this->end();++it) + if(it->second != NULL) + delete it->second ; + + std::map::clear() ; + } +}; + +template +class RsGxsMetaDataTemporaryMapVector: public std::map > +{ +public: + virtual ~RsGxsMetaDataTemporaryMapVector() + { + clear() ; + } + + virtual void clear() + { + for(typename RsGxsMetaDataTemporaryMapVector::iterator it = this->begin();it!=this->end();++it) + { + for(uint32_t i=0;isecond.size();++i) + delete it->second[i] ; + + it->second.clear(); + } + + std::map >::clear() ; + } +}; +#ifdef UNUSED +template +class RsGxsMetaDataTemporaryMapVector: public std::vector +{ +public: + virtual ~RsGxsMetaDataTemporaryMapVector() + { + clear() ; + } + + virtual void clear() + { + for(typename RsGxsMetaDataTemporaryMapVector::iterator it = this->begin();it!=this->end();++it) + if(it->second != NULL) + delete it->second ; + std::vector::clear() ; + } +}; +#endif + + inline RsGxsGrpMsgIdPair getMsgIdPair(RsNxsMsg& msg) { return RsGxsGrpMsgIdPair(std::make_pair(msg.grpId, msg.msgId)); diff --git a/libretroshare/src/services/p3gxscircles.cc b/libretroshare/src/services/p3gxscircles.cc index 05812d699..9936c202e 100644 --- a/libretroshare/src/services/p3gxscircles.cc +++ b/libretroshare/src/services/p3gxscircles.cc @@ -1978,7 +1978,7 @@ bool p3GxsCircles::processMembershipRequests(uint32_t token) #ifdef DEBUG_CIRCLES std::cerr << "Processing circle membership requests." << std::endl; #endif - GxsMsgDataMap msgItems ; + RsGxsMetaDataTemporaryMapVector msgItems; if(!RsGenExchange::getMsgData(token, msgItems)) {