Fixed some memory leaks and double frees in RsGxsNetService.

git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@6536 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
thunder2 2013-07-23 22:04:24 +00:00
parent 504ab562cc
commit 9d61832a86

View File

@ -691,6 +691,9 @@ bool RsGxsNetService::locked_processTransac(RsNxsTransac* item)
// initiating an incoming transaction // initiating an incoming transaction
if(item->transactFlag & RsNxsTransac::FLAG_BEGIN_P1){ if(item->transactFlag & RsNxsTransac::FLAG_BEGIN_P1){
if(transExists)
return false; // should not happen!
// create a transaction if the peer does not exist // create a transaction if the peer does not exist
if(!peerTrExists){ if(!peerTrExists){
mTransactions[peer] = TransactionIdMap(); mTransactions[peer] = TransactionIdMap();
@ -698,8 +701,6 @@ bool RsGxsNetService::locked_processTransac(RsNxsTransac* item)
TransactionIdMap& transMap = mTransactions[peer]; TransactionIdMap& transMap = mTransactions[peer];
if(transExists)
return false; // should not happen!
// create new transaction // create new transaction
tr = new NxsTransaction(); tr = new NxsTransaction();
@ -787,14 +788,14 @@ void RsGxsNetService::processTransactions(){
mmit_end = transMap.end(); mmit_end = transMap.end();
// transaction to be removed
std::list<uint32_t> toRemove;
/*! /*!
* Transactions owned by peer * Transactions owned by peer
*/ */
if(mit->first == mOwnId){ if(mit->first == mOwnId){
// transaction to be removed
std::list<uint32_t> toRemove;
for(; mmit != mmit_end; mmit++){ for(; mmit != mmit_end; mmit++){
NxsTransaction* tr = mmit->second; NxsTransaction* tr = mmit->second;
@ -814,6 +815,7 @@ void RsGxsNetService::processTransactions(){
tr->mFlag = NxsTransaction::FLAG_STATE_FAILED; tr->mFlag = NxsTransaction::FLAG_STATE_FAILED;
toRemove.push_back(transN); toRemove.push_back(transN);
mComplTransactions.push_back(tr);
continue; continue;
} }
@ -855,13 +857,6 @@ void RsGxsNetService::processTransactions(){
} }
} }
std::list<uint32_t>::iterator lit = toRemove.begin();
for(; lit != toRemove.end(); lit++)
{
transMap.erase(*lit);
}
}else{ }else{
/*! /*!
@ -875,8 +870,6 @@ void RsGxsNetService::processTransactions(){
* involved in transaction * involved in transaction
*/ */
std::list<uint32_t> toRemove;
for(; mmit != mmit_end; mmit++){ for(; mmit != mmit_end; mmit++){
NxsTransaction* tr = mmit->second; NxsTransaction* tr = mmit->second;
@ -895,6 +888,7 @@ void RsGxsNetService::processTransactions(){
tr->mFlag = NxsTransaction::FLAG_STATE_FAILED; tr->mFlag = NxsTransaction::FLAG_STATE_FAILED;
toRemove.push_back(transN); toRemove.push_back(transN);
mComplTransactions.push_back(tr);
continue; continue;
} }
@ -948,6 +942,7 @@ void RsGxsNetService::processTransactions(){
tr->mFlag = NxsTransaction::FLAG_STATE_FAILED; // flag as a failed transaction tr->mFlag = NxsTransaction::FLAG_STATE_FAILED; // flag as a failed transaction
} }
} }
}
std::list<uint32_t>::iterator lit = toRemove.begin(); std::list<uint32_t>::iterator lit = toRemove.begin();
@ -955,7 +950,7 @@ void RsGxsNetService::processTransactions(){
{ {
transMap.erase(*lit); transMap.erase(*lit);
} }
}
} }
} }
@ -1203,16 +1198,12 @@ void RsGxsNetService::locked_genReqMsgTransaction(NxsTransaction* tr)
std::cerr << "RsGxsNetService::genReqMsgTransaction(): item failed cast to RsNxsSyncMsgItem* " std::cerr << "RsGxsNetService::genReqMsgTransaction(): item failed cast to RsNxsSyncMsgItem* "
<< std::endl; << std::endl;
#endif #endif
delete item;
item = NULL;
} }
} }
if(msgItemL.empty()) if(msgItemL.empty())
return; return;
// get grp id for this transaction // get grp id for this transaction
RsNxsSyncMsgItem* item = msgItemL.front(); RsNxsSyncMsgItem* item = msgItemL.front();
const std::string& grpId = item->grpId; const std::string& grpId = item->grpId;
@ -1251,12 +1242,15 @@ void RsGxsNetService::locked_genReqMsgTransaction(NxsTransaction* tr)
// put ids in set for each searching // put ids in set for each searching
for(; vit != msgMetaV.end(); vit++) for(; vit != msgMetaV.end(); vit++)
{
msgIdSet.insert((*vit)->mMsgId); msgIdSet.insert((*vit)->mMsgId);
delete(*vit);
}
msgMetaV.clear();
// get unique id for this transaction // get unique id for this transaction
uint32_t transN = locked_getTransactionId(); uint32_t transN = locked_getTransactionId();
// add msgs that you don't have to request list // add msgs that you don't have to request list
std::list<RsNxsSyncMsgItem*>::iterator llit = msgItemL.begin(); std::list<RsNxsSyncMsgItem*>::iterator llit = msgItemL.begin();
std::list<RsNxsItem*> reqList; std::list<RsNxsItem*> reqList;
@ -1272,7 +1266,6 @@ void RsGxsNetService::locked_genReqMsgTransaction(NxsTransaction* tr)
if(msgIdSet.find(msgId) == msgIdSet.end()){ if(msgIdSet.find(msgId) == msgIdSet.end()){
if(mReputations->haveReputation(syncItem->authorId) || syncItem->authorId.empty()) if(mReputations->haveReputation(syncItem->authorId) || syncItem->authorId.empty())
{ {
GixsReputation rep; GixsReputation rep;
@ -1369,8 +1362,6 @@ void RsGxsNetService::locked_genReqGrpTransaction(NxsTransaction* tr)
std::cerr << "RsGxsNetService::genReqGrpTransaction(): item failed to caste to RsNxsSyncMsgItem* " std::cerr << "RsGxsNetService::genReqGrpTransaction(): item failed to caste to RsNxsSyncMsgItem* "
<< std::endl; << std::endl;
#endif #endif
delete item;
item = NULL;
} }
} }
@ -1465,7 +1456,16 @@ void RsGxsNetService::locked_genSendGrpsTransaction(NxsTransaction* tr)
for(;lit != tr->mItems.end(); lit++) for(;lit != tr->mItems.end(); lit++)
{ {
RsNxsSyncGrpItem* item = dynamic_cast<RsNxsSyncGrpItem*>(*lit); RsNxsSyncGrpItem* item = dynamic_cast<RsNxsSyncGrpItem*>(*lit);
if (item)
{
grps[item->grpId] = NULL; grps[item->grpId] = NULL;
}else
{
#ifdef NXS_NET_DEBUG
std::cerr << "RsGxsNetService::locked_genSendGrpsTransaction(): item failed to caste to RsNxsSyncGrpItem* "
<< std::endl;
#endif
}
} }
if(!grps.empty()) if(!grps.empty())
@ -1619,8 +1619,18 @@ void RsGxsNetService::locked_genSendMsgsTransaction(NxsTransaction* tr)
for(;lit != tr->mItems.end(); lit++) for(;lit != tr->mItems.end(); lit++)
{ {
RsNxsSyncMsgItem* item = dynamic_cast<RsNxsSyncMsgItem*>(*lit); RsNxsSyncMsgItem* item = dynamic_cast<RsNxsSyncMsgItem*>(*lit);
if (item)
{
msgIds[item->grpId].push_back(item->msgId); msgIds[item->grpId].push_back(item->msgId);
} }
else
{
#ifdef NXS_NET_DEBUG
std::cerr << "RsGxsNetService::locked_genSendMsgsTransaction(): item failed to caste to RsNxsSyncMsgItem* "
<< std::endl;
#endif
}
}
mDataStore->retrieveNxsMsgs(msgIds, msgs, false, false); mDataStore->retrieveNxsMsgs(msgIds, msgs, false, false);