diff --git a/libretroshare/src/chat/p3chatservice.cc b/libretroshare/src/chat/p3chatservice.cc index 60894684a..adaab4c1e 100644 --- a/libretroshare/src/chat/p3chatservice.cc +++ b/libretroshare/src/chat/p3chatservice.cc @@ -1199,6 +1199,7 @@ bool p3ChatService::loadList(std::list& load) delete *it; } + load.clear() ; return true; } diff --git a/libretroshare/src/dbase/cachestrapper.cc b/libretroshare/src/dbase/cachestrapper.cc index c9c1c8b59..da56e207d 100644 --- a/libretroshare/src/dbase/cachestrapper.cc +++ b/libretroshare/src/dbase/cachestrapper.cc @@ -1052,6 +1052,7 @@ bool CacheStrapper::loadList(std::list& load) delete (*it); } } + load.clear() ; /* assemble a list of dirs to clean (union of cache dirs) */ std::list cacheDirs; diff --git a/libretroshare/src/dht/p3bitdht_relay.cc b/libretroshare/src/dht/p3bitdht_relay.cc index 556219772..8b04a3e2f 100644 --- a/libretroshare/src/dht/p3bitdht_relay.cc +++ b/libretroshare/src/dht/p3bitdht_relay.cc @@ -279,6 +279,11 @@ bool p3BitDht::loadList(std::list& load) /* error */ std::cerr << "p3BitDht::loadList() Error only expecting 1 item"; std::cerr << std::endl; + + for(std::list::iterator it=load.begin();it!=load.end();++it) + delete *it ; + + load.clear() ; return false; } RsItem *item = load.front(); @@ -290,6 +295,7 @@ bool p3BitDht::loadList(std::list& load) /* error */ std::cerr << "p3BitDht::loadList() Error expecting item = config"; std::cerr << std::endl; + delete item ; return false; } @@ -393,6 +399,7 @@ bool p3BitDht::loadList(std::list& load) setRelayMode(mode); } + load.clear() ; return true; } diff --git a/libretroshare/src/ft/ftcontroller.cc b/libretroshare/src/ft/ftcontroller.cc index 325375ba0..b58650a1a 100644 --- a/libretroshare/src/ft/ftcontroller.cc +++ b/libretroshare/src/ft/ftcontroller.cc @@ -2224,6 +2224,7 @@ bool ftController::loadList(std::list& load) /* cleanup */ delete (*it); } + load.clear() ; return true; } diff --git a/libretroshare/src/ft/ftdbase.cc b/libretroshare/src/ft/ftdbase.cc index 25cbe65f2..fd0285552 100644 --- a/libretroshare/src/ft/ftdbase.cc +++ b/libretroshare/src/ft/ftdbase.cc @@ -328,6 +328,8 @@ bool ftFiMonitor::loadList(std::list& load) if(sscanf(mit->second.c_str(),"%d",&t) == 1) setWatchPeriod(t); } + delete *it ; + continue ; } RsFileConfigItem *fi = dynamic_cast(*it); @@ -348,10 +350,13 @@ bool ftFiMonitor::loadList(std::list& load) info.shareflags &= ~DIR_FLAGS_NETWORK_WIDE_GROUPS ; // disabling this flag for know, for consistency reasons dirList.push_back(info) ; + + delete *it ; } /* set directories */ setSharedDirectories(dirList); + load.clear() ; return true; } diff --git a/libretroshare/src/ft/ftextralist.cc b/libretroshare/src/ft/ftextralist.cc index 7ff5fb681..d2fb76151 100644 --- a/libretroshare/src/ft/ftextralist.cc +++ b/libretroshare/src/ft/ftextralist.cc @@ -484,6 +484,7 @@ bool ftExtraList::loadList(std::list& load) /********************************** WINDOWS/UNIX SPECIFIC PART ******************/ } + load.clear() ; return true; } diff --git a/libretroshare/src/grouter/p3grouter.cc b/libretroshare/src/grouter/p3grouter.cc index 17e03735d..b4faf9ccb 100644 --- a/libretroshare/src/grouter/p3grouter.cc +++ b/libretroshare/src/grouter/p3grouter.cc @@ -2095,6 +2095,7 @@ bool p3GRouter::loadList(std::list& items) #ifdef GROUTER_DEBUG debugDump(); #endif + items.clear() ; return true ; } bool p3GRouter::saveList(bool& cleanup,std::list& items) diff --git a/libretroshare/src/gxs/rsgxsnetservice.cc b/libretroshare/src/gxs/rsgxsnetservice.cc index a5c3ea720..79107197a 100644 --- a/libretroshare/src/gxs/rsgxsnetservice.cc +++ b/libretroshare/src/gxs/rsgxsnetservice.cc @@ -310,6 +310,18 @@ RsGxsNetService::~RsGxsNetService() it->second.clear() ; } mTransactions.clear() ; + + delete mGrpServerUpdateItem ; + + for(ClientGrpMap::iterator it = mClientGrpUpdateMap.begin();it!=mClientGrpUpdateMap.end();++it) + delete it->second ; + + mClientGrpUpdateMap.clear() ; + + for(std::map::iterator it(mServerMsgUpdateMap.begin());it!=mServerMsgUpdateMap.end();) + delete it->second ; + + mServerMsgUpdateMap.clear() ; } @@ -1310,9 +1322,7 @@ public: else if((gsui = dynamic_cast(item)) != NULL) { if(mServerGrpUpdateItem == NULL) - { mServerGrpUpdateItem = gsui; - } else { std::cerr << "Error! More than one server group update item exists!" << std::endl; @@ -1320,7 +1330,10 @@ public: } } else + { std::cerr << "Type not expected!" << std::endl; + delete item ; + } } private: @@ -1336,9 +1349,11 @@ bool RsGxsNetService::loadList(std::list &load) { RS_STACK_MUTEX(mNxsMutex) ; + // The delete is done in StoreHere, if necessary + std::for_each(load.begin(), load.end(), StoreHere(mClientGrpUpdateMap, mClientMsgUpdateMap, mServerMsgUpdateMap, mGrpServerUpdateItem)); time_t now = time(NULL); - + for(ClientMsgMap::iterator it = mClientMsgUpdateMap.begin();it!=mClientMsgUpdateMap.end();++it) for(std::map::const_iterator it2(it->second->msgUpdateInfos.begin());it2!=it->second->msgUpdateInfos.end();++it2) { diff --git a/libretroshare/src/plugins/rscacheservice.h b/libretroshare/src/plugins/rscacheservice.h index 8f1fcce65..6e928da61 100644 --- a/libretroshare/src/plugins/rscacheservice.h +++ b/libretroshare/src/plugins/rscacheservice.h @@ -20,8 +20,8 @@ class RsCacheService: public CacheSource, public CacheStore, public p3Config // Functions from p3config // virtual RsSerialiser *setupSerialiser() { return NULL ; } - virtual bool saveList(bool&, std::list&) { return false ;} - virtual bool loadList(std::list&) { return false ;} + virtual bool saveList(bool&, std::list&) =0; + virtual bool loadList(std::list&) =0; private: uint32_t _tick_delay_in_seconds ; diff --git a/libretroshare/src/plugins/rspqiservice.h b/libretroshare/src/plugins/rspqiservice.h index 4d445b0d8..f4ee6f313 100644 --- a/libretroshare/src/plugins/rspqiservice.h +++ b/libretroshare/src/plugins/rspqiservice.h @@ -17,8 +17,8 @@ class RsPQIService: public p3Service, public p3Config // Functions from p3config // virtual RsSerialiser *setupSerialiser() { return NULL ; } - virtual bool saveList(bool&, std::list&) { return false ;} - virtual bool loadList(std::list&) { return false ;} + virtual bool saveList(bool&, std::list&) =0 ; + virtual bool loadList(std::list&) =0 ; private: uint32_t _tick_delay_in_seconds ; diff --git a/libretroshare/src/pqi/authgpg.cc b/libretroshare/src/pqi/authgpg.cc index 36b08342c..3a8a06b2f 100644 --- a/libretroshare/src/pqi/authgpg.cc +++ b/libretroshare/src/pqi/authgpg.cc @@ -715,6 +715,7 @@ bool AuthGPG::loadList(std::list& load) } delete (*it); } + load.clear() ; return true; } diff --git a/libretroshare/src/pqi/authssl.cc b/libretroshare/src/pqi/authssl.cc index 274187f5b..27cae90f6 100644 --- a/libretroshare/src/pqi/authssl.cc +++ b/libretroshare/src/pqi/authssl.cc @@ -1705,6 +1705,7 @@ bool AuthSSLimpl::loadList(std::list& load) } delete (*it); } + load.clear() ; return true; } diff --git a/libretroshare/src/pqi/p3historymgr.cc b/libretroshare/src/pqi/p3historymgr.cc index 04e97f08a..f2673cd1e 100644 --- a/libretroshare/src/pqi/p3historymgr.cc +++ b/libretroshare/src/pqi/p3historymgr.cc @@ -307,7 +307,8 @@ bool p3HistoryMgr::loadList(std::list& load) RsHistoryMsgItem *msgItem; std::list::iterator it; - for (it = load.begin(); it != load.end(); ++it) { + for (it = load.begin(); it != load.end(); ++it) + { if (NULL != (msgItem = dynamic_cast(*it))) { std::map >::iterator mit = mMessages.find(msgItem->chatPeerId); @@ -381,6 +382,7 @@ bool p3HistoryMgr::loadList(std::list& load) delete (*it); } + load.clear() ; return true; } diff --git a/libretroshare/src/pqi/p3peermgr.cc b/libretroshare/src/pqi/p3peermgr.cc index bcde912ef..79978277c 100644 --- a/libretroshare/src/pqi/p3peermgr.cc +++ b/libretroshare/src/pqi/p3peermgr.cc @@ -2360,6 +2360,7 @@ bool p3PeerMgrIMPL::loadList(std::list& load) setProxyServerAddress(RS_HIDDEN_TYPE_I2P, proxy_addr); } + load.clear() ; return true; } diff --git a/libretroshare/src/pqi/p3servicecontrol.cc b/libretroshare/src/pqi/p3servicecontrol.cc index 820b29a4c..45a9f6c5a 100644 --- a/libretroshare/src/pqi/p3servicecontrol.cc +++ b/libretroshare/src/pqi/p3servicecontrol.cc @@ -1180,12 +1180,13 @@ bool p3ServiceControl::loadList(std::list& loadList) { RsServicePermissionItem *item = dynamic_cast(*it) ; - if(item == NULL) - continue ; - - mServicePermissionMap[item->mServiceId] = *item ; + if(item != NULL) + mServicePermissionMap[item->mServiceId] = *item ; + + delete *it ; } + loadList.clear() ; return true; } diff --git a/libretroshare/src/services/p3banlist.cc b/libretroshare/src/services/p3banlist.cc index 520a4dbea..94b9487fd 100644 --- a/libretroshare/src/services/p3banlist.cc +++ b/libretroshare/src/services/p3banlist.cc @@ -885,6 +885,7 @@ bool p3BanList::loadList(std::list& load) delete *it ; } + load.clear() ; return true ; } diff --git a/libretroshare/src/services/p3gxsreputation.cc b/libretroshare/src/services/p3gxsreputation.cc index 8715ffad2..dd7a46da4 100644 --- a/libretroshare/src/services/p3gxsreputation.cc +++ b/libretroshare/src/services/p3gxsreputation.cc @@ -793,6 +793,7 @@ bool p3GxsReputation::loadList(std::list& loadList) delete (*it); } + loadList.clear() ; return true; } diff --git a/libretroshare/src/services/p3idservice.cc b/libretroshare/src/services/p3idservice.cc index 37fddb5db..7aa2aea06 100644 --- a/libretroshare/src/services/p3idservice.cc +++ b/libretroshare/src/services/p3idservice.cc @@ -275,6 +275,7 @@ bool p3IdService::loadList(std::list& items) RsGxsIdLocalInfoItem *lii; for(std::list::const_iterator it = items.begin();it!=items.end();++it) + { if( (lii = dynamic_cast(*it)) != NULL) { for(std::map::const_iterator it2 = lii->mTimeStamps.begin();it2!=lii->mTimeStamps.end();++it2) @@ -282,7 +283,11 @@ bool p3IdService::loadList(std::list& items) mContacts = lii->mContacts ; } + + delete *it ; + } + items.clear() ; return true ; } diff --git a/libretroshare/src/services/p3msgservice.cc b/libretroshare/src/services/p3msgservice.cc index bc7e34317..2b5618595 100644 --- a/libretroshare/src/services/p3msgservice.cc +++ b/libretroshare/src/services/p3msgservice.cc @@ -544,7 +544,7 @@ bool p3MsgService::loadList(std::list& load) RsMsgSrcId* msi; RsMsgParentId* msp; RsMsgGRouterMap* grm; -// RsPublicMsgInviteConfigItem* msv; + // RsPublicMsgInviteConfigItem* msv; std::list items; std::list::iterator it; @@ -552,150 +552,155 @@ bool p3MsgService::loadList(std::list& load) std::map srcIdMsgMap; std::map::iterator srcIt; - // load items and calculate next unique msgId - for(it = load.begin(); it != load.end(); ++it) - { + // load items and calculate next unique msgId + for(it = load.begin(); it != load.end(); ++it) + { - if (NULL != (mitem = dynamic_cast(*it))) - { - /* STORE MsgID */ - if (mitem->msgId >= mMsgUniqueId) { - mMsgUniqueId = mitem->msgId + 1; - } - items.push_back(mitem); - } - else if (NULL != (grm = dynamic_cast(*it))) - { - // merge. - for(std::map::const_iterator it(grm->ongoing_msgs.begin());it!=grm->ongoing_msgs.end();++it) - _ongoing_messages.insert(*it) ; - } - else if(NULL != (mtt = dynamic_cast(*it))) - { - // 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)); - } + if (NULL != (mitem = dynamic_cast(*it))) + { + /* STORE MsgID */ + if (mitem->msgId >= mMsgUniqueId) { + mMsgUniqueId = mitem->msgId + 1; + } + items.push_back(mitem); + } + else if (NULL != (grm = dynamic_cast(*it))) + { + // merge. + for(std::map::const_iterator it(grm->ongoing_msgs.begin());it!=grm->ongoing_msgs.end();++it) + _ongoing_messages.insert(*it) ; + } + else if(NULL != (mtt = dynamic_cast(*it))) + { + // 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))) - { - mMsgTags.insert(std::pair(mti->msgId, mti)); - } - else if(NULL != (msi = dynamic_cast(*it))) - { - srcIdMsgMap.insert(std::pair(msi->msgId, msi->srcId)); - mSrcIds.insert(std::pair(msi->msgId, msi)); // does not need to be kept - } - else if(NULL != (msp = dynamic_cast(*it))) - { - mParentId.insert(std::pair(msp->msgId, msp)); - } + } + else if(NULL != (mti = dynamic_cast(*it))) + { + mMsgTags.insert(std::pair(mti->msgId, mti)); + } + else if(NULL != (msi = dynamic_cast(*it))) + { + srcIdMsgMap.insert(std::pair(msi->msgId, msi->srcId)); + mSrcIds.insert(std::pair(msi->msgId, msi)); // does not need to be kept + } + else if(NULL != (msp = dynamic_cast(*it))) + { + mParentId.insert(std::pair(msp->msgId, msp)); + } - RsConfigKeyValueSet *vitem = NULL ; + RsConfigKeyValueSet *vitem = NULL ; - if(NULL != (vitem = dynamic_cast(*it))) - for(std::list::const_iterator kit = vitem->tlvkvs.pairs.begin(); kit != vitem->tlvkvs.pairs.end(); ++kit) - { - if(kit->key == "DISTANT_MESSAGES_ENABLED") - { + if(NULL != (vitem = dynamic_cast(*it))) + { + for(std::list::const_iterator kit = vitem->tlvkvs.pairs.begin(); kit != vitem->tlvkvs.pairs.end(); ++kit) + { + if(kit->key == "DISTANT_MESSAGES_ENABLED") + { #ifdef MSG_DEBUG - std::cerr << "Loaded config default nick name for distant chat: " << kit->value << std::endl ; + std::cerr << "Loaded config default nick name for distant chat: " << kit->value << std::endl ; #endif - mShouldEnableDistantMessaging = (kit->value == "YES") ; - } - if(kit->key == "DISTANT_MESSAGE_PERMISSION_FLAGS") - { + mShouldEnableDistantMessaging = (kit->value == "YES") ; + } + if(kit->key == "DISTANT_MESSAGE_PERMISSION_FLAGS") + { #ifdef MSG_DEBUG - std::cerr << "Loaded distant message permission flags: " << kit->value << std::endl ; + std::cerr << "Loaded distant message permission flags: " << kit->value << std::endl ; #endif - if (!kit->value.empty()) - { - std::istringstream is(kit->value) ; + if (!kit->value.empty()) + { + std::istringstream is(kit->value) ; - uint32_t tmp ; - is >> tmp ; + uint32_t tmp ; + is >> tmp ; - if(tmp < 3) - mDistantMessagePermissions = tmp ; - else - std::cerr << "(EE) Invalid value read for DistantMessagePermission flags in config: " << tmp << std::endl; - } - } - } + if(tmp < 3) + mDistantMessagePermissions = tmp ; + else + std::cerr << "(EE) Invalid value read for DistantMessagePermission flags in config: " << tmp << std::endl; + } + } + } - } + delete *it ; + continue ; + } + } + load.clear() ; - // sort items into lists - std::list::iterator msgIt; - for (msgIt = items.begin(); msgIt != items.end(); ++msgIt) - { - mitem = *msgIt; + // sort items into lists + std::list::iterator msgIt; + for (msgIt = items.begin(); msgIt != items.end(); ++msgIt) + { + mitem = *msgIt; - /* STORE MsgID */ - if (mitem->msgId == 0) { + /* STORE MsgID */ + if (mitem->msgId == 0) { mitem->msgId = getNewUniqueMsgId(); - } + } - RsStackMutex stack(mMsgMtx); /********** STACK LOCKED MTX ******/ + RsStackMutex stack(mMsgMtx); /********** STACK LOCKED MTX ******/ - srcIt = srcIdMsgMap.find(mitem->msgId); - if(srcIt != srcIdMsgMap.end()) { - mitem->PeerId(srcIt->second); - srcIdMsgMap.erase(srcIt); - } + srcIt = srcIdMsgMap.find(mitem->msgId); + if(srcIt != srcIdMsgMap.end()) { + mitem->PeerId(srcIt->second); + srcIdMsgMap.erase(srcIt); + } - /* switch depending on the PENDING + /* switch depending on the PENDING * flags */ - if (mitem -> msgFlags & RS_MSG_FLAGS_PENDING) - { + if (mitem -> msgFlags & RS_MSG_FLAGS_PENDING) + { - //std::cerr << "MSG_PENDING"; - //std::cerr << std::endl; - //mitem->print(std::cerr); + //std::cerr << "MSG_PENDING"; + //std::cerr << std::endl; + //mitem->print(std::cerr); - msgOutgoing[mitem->msgId] = mitem; - } - else - { - imsg[mitem->msgId] = mitem; - } - } + msgOutgoing[mitem->msgId] = mitem; + } + else + { + imsg[mitem->msgId] = mitem; + } + } - RsStackMutex stack(mMsgMtx); /********** STACK LOCKED MTX ******/ + RsStackMutex stack(mMsgMtx); /********** STACK LOCKED MTX ******/ - /* remove missing msgId in mSrcIds */ - for (srcIt = srcIdMsgMap.begin(); srcIt != srcIdMsgMap.end(); ++srcIt) { - std::map::iterator it = mSrcIds.find(srcIt->first); - if (it != mSrcIds.end()) { - delete(it->second); - mSrcIds.erase(it); - } - } + /* remove missing msgId in mSrcIds */ + for (srcIt = srcIdMsgMap.begin(); srcIt != srcIdMsgMap.end(); ++srcIt) { + std::map::iterator it = mSrcIds.find(srcIt->first); + if (it != mSrcIds.end()) { + delete(it->second); + mSrcIds.erase(it); + } + } - /* remove missing msgId in mParentId */ - std::map::iterator mit = mParentId.begin(); - while (mit != mParentId.end()) { - if (imsg.find(mit->first) == imsg.end()) { - if (msgOutgoing.find(mit->first) == msgOutgoing.end()) { - /* not found */ - mParentId.erase(mit++); - continue; - } - } - - ++mit; - } - - return true; + /* remove missing msgId in mParentId */ + std::map::iterator mit = mParentId.begin(); + while (mit != mParentId.end()) { + if (imsg.find(mit->first) == imsg.end()) { + if (msgOutgoing.find(mit->first) == msgOutgoing.end()) { + /* not found */ + mParentId.erase(mit++); + continue; + } + } + + ++mit; + } + + return true; } void p3MsgService::loadWelcomeMsg() diff --git a/libretroshare/src/services/p3statusservice.cc b/libretroshare/src/services/p3statusservice.cc index 533672d60..c80740462 100644 --- a/libretroshare/src/services/p3statusservice.cc +++ b/libretroshare/src/services/p3statusservice.cc @@ -309,42 +309,34 @@ bool p3StatusService::saveList(bool& cleanup, std::list& ilist){ return true; } -bool p3StatusService::loadList(std::list& load){ - - // load your status from last rs session - StatusInfo own_info; - std::list::const_iterator it = load.begin(); - - if(it == load.end()){ - std::cerr << "p3StatusService::loadList(): Failed to load " << std::endl; - return false; - } - - for(; it != load.end(); ++it){ - RsStatusItem* own_status = dynamic_cast(*it); +bool p3StatusService::loadList(std::list& load) +{ + // load your status from last rs session + StatusInfo own_info; - if(own_status != NULL){ + for(std::list::const_iterator it = load.begin() ; it != load.end(); ++it) + { + RsStatusItem* own_status = dynamic_cast(*it); - own_info.id = mServiceCtrl->getOwnId(); - own_info.status = own_status->status; - own_info.time_stamp = own_status->sendTime; - delete own_status; + if(own_status != NULL) + { + own_info.id = mServiceCtrl->getOwnId(); + own_info.status = own_status->status; + own_info.time_stamp = own_status->sendTime; - { - RsStackMutex stack(mStatusMtx); - std::pair pr(mServiceCtrl->getOwnId(), own_info); - mStatusInfoMap.insert(pr); - } + { + RsStackMutex stack(mStatusMtx); + std::pair pr(mServiceCtrl->getOwnId(), own_info); + mStatusInfoMap.insert(pr); + } - return true; - }else{ - std::cerr << "p3StatusService::loadList " << "Failed to load list " - << std::endl; - } + } - } - return false; + delete *it ; + } + load.clear() ; + return false; } diff --git a/libretroshare/src/turtle/p3turtle.cc b/libretroshare/src/turtle/p3turtle.cc index aaac2ef08..4fc818018 100644 --- a/libretroshare/src/turtle/p3turtle.cc +++ b/libretroshare/src/turtle/p3turtle.cc @@ -728,6 +728,7 @@ bool p3turtle::loadList(std::list& load) delete vitem ; } + load.clear() ; return true ; } int p3turtle::getMaxTRForwardRate() const diff --git a/plugins/VOIP/services/p3VOIP.cc b/plugins/VOIP/services/p3VOIP.cc index c0867299d..d5cc4b06b 100644 --- a/plugins/VOIP/services/p3VOIP.cc +++ b/plugins/VOIP/services/p3VOIP.cc @@ -783,7 +783,8 @@ bool p3VOIP::loadList(std::list& load) delete vitem ; } - + + load.clear() ; return true ; }