From b0483a0c38c54795a4b4c582396d622a4465dce7 Mon Sep 17 00:00:00 2001 From: csoler Date: Wed, 26 Jul 2017 10:23:18 +0200 Subject: [PATCH] fixed bug in removeDeleteExistingMsgs() --- libretroshare/src/gxs/rsgenexchange.cc | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/libretroshare/src/gxs/rsgenexchange.cc b/libretroshare/src/gxs/rsgenexchange.cc index 7028d6295..573ff5c6b 100644 --- a/libretroshare/src/gxs/rsgenexchange.cc +++ b/libretroshare/src/gxs/rsgenexchange.cc @@ -3340,7 +3340,7 @@ void RsGenExchange::removeDeleteExistingMessages( std::list& msgs, Gx } // now for each msg to be stored that exist in the retrieved msg/grp "index" delete and erase from map - for(std::list::iterator cit2 = msgs.begin(); cit2 != msgs.end(); ++cit2) + for(std::list::iterator cit2 = msgs.begin(); cit2 != msgs.end();) { const RsGxsMessageId::std_vector& msgIds = msgIdReq[(*cit2)->metaData->mGroupId]; @@ -3352,7 +3352,8 @@ void RsGenExchange::removeDeleteExistingMessages( std::list& msgs, Gx // if(std::find(msgIds.begin(), msgIds.end(), (*cit2)->metaData->mMsgId) != msgIds.end() || !messagePublicationTest( *(*cit2)->metaData)) { - // msg exist in retrieved index + // msg exist in retrieved index. We should use a std::set here instead of a vector. + RsGxsMessageId::std_vector& notifyIds = msgIdsNotify[ (*cit2)->metaData->mGroupId]; RsGxsMessageId::std_vector::iterator it2 = std::find(notifyIds.begin(), notifyIds.end(), (*cit2)->metaData->mMsgId); if(it2 != notifyIds.end()) @@ -3368,9 +3369,10 @@ void RsGenExchange::removeDeleteExistingMessages( std::list& msgs, Gx #endif delete *cit2; - msgs.erase(cit2); - // cit2->second will be deleted too in the destructor of cit2->first (RsNxsMsg) + cit2 = msgs.erase(cit2); } + else + ++cit2; } }