From baac505c153e06658bbd725e7c1415f0b06a7ecd Mon Sep 17 00:00:00 2001 From: chrisparker126 Date: Sat, 25 Sep 2010 12:54:34 +0000 Subject: [PATCH] removed memory leak caused by moving initretroshare to msgservice onstructor git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@3540 b45a01b8-16f6-495d-af2f-9b41ad6348cc --- libretroshare/src/services/p3msgservice.cc | 29 ++++++++++++++++------ 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/libretroshare/src/services/p3msgservice.cc b/libretroshare/src/services/p3msgservice.cc index d20ca2ff5..e1f3d802b 100644 --- a/libretroshare/src/services/p3msgservice.cc +++ b/libretroshare/src/services/p3msgservice.cc @@ -38,6 +38,7 @@ #include #include +#include const int msgservicezone = 54319; @@ -274,12 +275,15 @@ int p3MsgService::checkOutgoingMessages() std::list p3MsgService::saveList(bool& cleanup) { + std::list itemList; std::map::iterator mit; std::map::iterator mit2; std::map::iterator mit3; + MsgTagType stdTags; + cleanup = false; mMsgMtx.lock(); @@ -290,8 +294,8 @@ std::list p3MsgService::saveList(bool& cleanup) for(mit = msgOutgoing.begin(); mit != msgOutgoing.end(); mit++) itemList.push_back(mit->second) ; - for(mit2 = mTags.begin(); mit2 != mTags.end(); mit2++) - itemList.push_back(mit2->second); + for(mit2 = mTags.begin(); mit2 != mTags.end(); mit2++) + itemList.push_back(mit2->second); for(mit3 = mMsgTags.begin(); mit3 != mMsgTags.end(); mit3++) itemList.push_back(mit3->second); @@ -355,14 +359,14 @@ void p3MsgService::initStandardTagTypes() bool p3MsgService::loadList(std::list load) { - RsMsgItem *mitem; RsMsgTagType* mtt; RsMsgTags* mti; std::list items; - std::list::iterator it; + std::list::iterator it; + std::map::iterator tagIt; // load items and calculate next unique msgId for(it = load.begin(); it != load.end(); it++) @@ -377,8 +381,19 @@ bool p3MsgService::loadList(std::list load) items.push_back(mitem); } else if(NULL != (mtt = dynamic_cast(*it))) - { - mTags.insert(std::pair(mtt->tagId, mtt)); + { + // delete standard tags as they are now save in config + if(mTags.end() == (tagIt = mTags.find(mtt->tagId))) + { + mTags.insert(std::pair(mtt->tagId, mtt)); + } + else + { + delete mTags[mtt->tagId]; + mTags.erase(tagIt); + mTags.insert(std::pair(mtt->tagId, mtt)); + } + } else if(NULL != (mti = dynamic_cast(*it))) { @@ -1003,7 +1018,7 @@ bool p3MsgService::setMessageTag(std::string &msgId, uint32_t tagId, bool set) bool p3MsgService::resetMessageStandardTagTypes(MsgTagType& tags) { MsgTagType standardTags; - getStandardTagTypes(standardTags); + getStandardTagTypes(standardTags); std::map >::iterator mit; for (mit = standardTags.types.begin(); mit != standardTags.types.end(); mit++) {