Fixed crash after last commit in p3idservice.cc.

Fixed memory leaks and possible crashs in ::getGroupData
- p3gxschannels
- p3gxscircles
- p3gxsforums
- p3idservice
- p3posted
- p3photoservice


git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@6524 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
thunder2 2013-07-21 01:50:13 +00:00
parent 3730645808
commit f5218cdfc3
7 changed files with 143 additions and 109 deletions

View File

@ -1109,7 +1109,6 @@ bool RsGenExchange::getMsgRelatedMeta(const uint32_t &token, GxsMsgRelatedMetaMa
bool RsGenExchange::getGroupData(const uint32_t &token, std::vector<RsGxsGrpItem *>& grpItem) bool RsGenExchange::getGroupData(const uint32_t &token, std::vector<RsGxsGrpItem *>& grpItem)
{ {
std::list<RsNxsGrp*> nxsGrps; std::list<RsNxsGrp*> nxsGrps;
bool ok = mDataAccess->getGroupData(token, nxsGrps); bool ok = mDataAccess->getGroupData(token, nxsGrps);
@ -1154,10 +1153,8 @@ bool RsGenExchange::getGroupData(const uint32_t &token, std::vector<RsGxsGrpItem
return ok; return ok;
} }
bool RsGenExchange::getMsgData(const uint32_t &token, bool RsGenExchange::getMsgData(const uint32_t &token, GxsMsgDataMap &msgItems)
GxsMsgDataMap &msgItems)
{ {
RsStackMutex stack(mGenMtx); RsStackMutex stack(mGenMtx);
NxsMsgDataResult msgResult; NxsMsgDataResult msgResult;
bool ok = mDataAccess->getMsgData(token, msgResult); bool ok = mDataAccess->getMsgData(token, msgResult);
@ -1170,16 +1167,14 @@ bool RsGenExchange::getMsgData(const uint32_t &token,
std::vector<RsGxsMsgItem*> gxsMsgItems; std::vector<RsGxsMsgItem*> gxsMsgItems;
const RsGxsGroupId& grpId = mit->first; const RsGxsGroupId& grpId = mit->first;
std::vector<RsNxsMsg*>& nxsMsgsV = mit->second; std::vector<RsNxsMsg*>& nxsMsgsV = mit->second;
std::vector<RsNxsMsg*>::iterator vit std::vector<RsNxsMsg*>::iterator vit = nxsMsgsV.begin();
= nxsMsgsV.begin();
for(; vit != nxsMsgsV.end(); vit++) for(; vit != nxsMsgsV.end(); vit++)
{ {
RsNxsMsg*& msg = *vit; RsNxsMsg*& msg = *vit;
RsItem* item = NULL; RsItem* item = NULL;
if(msg->msg.bin_len != 0) if(msg->msg.bin_len != 0)
item = mSerialiser->deserialise(msg->msg.bin_data, item = mSerialiser->deserialise(msg->msg.bin_data, &msg->msg.bin_len);
&msg->msg.bin_len);
if (item) if (item)
{ {

View File

@ -194,6 +194,7 @@ bool p3GxsChannels::getGroupData(const uint32_t &token, std::vector<RsGxsChannel
{ {
std::cerr << "p3GxsChannels::getGroupData() ERROR in decode"; std::cerr << "p3GxsChannels::getGroupData() ERROR in decode";
std::cerr << std::endl; std::cerr << std::endl;
delete(*vit);
} }
} }
} }

View File

@ -370,11 +370,20 @@ bool p3GxsCircles::getGroupData(const uint32_t &token, std::vector<RsGxsCircleGr
for(; vit != grpData.end(); vit++) for(; vit != grpData.end(); vit++)
{ {
RsGxsCircleGroupItem* item = dynamic_cast<RsGxsCircleGroupItem*>(*vit); RsGxsCircleGroupItem* item = dynamic_cast<RsGxsCircleGroupItem*>(*vit);
if (item)
{
RsGxsCircleGroup group; RsGxsCircleGroup group;
item->convertTo(group); item->convertTo(group);
// If its cached - add that info (TODO). // If its cached - add that info (TODO).
groups.push_back(group); groups.push_back(group);
delete(item);
}
else
{
std::cerr << "Not a RsGxsCircleGroupItem, deleting!" << std::endl;
delete *vit;
}
} }
} }

View File

@ -102,12 +102,20 @@ bool p3GxsForums::getGroupData(const uint32_t &token, std::vector<RsGxsForumGrou
for(; vit != grpData.end(); vit++) for(; vit != grpData.end(); vit++)
{ {
RsGxsForumGroupItem* item = dynamic_cast<RsGxsForumGroupItem*>(*vit); RsGxsForumGroupItem* item = dynamic_cast<RsGxsForumGroupItem*>(*vit);
if (item)
{
RsGxsForumGroup grp = item->mGroup; RsGxsForumGroup grp = item->mGroup;
item->mGroup.mMeta = item->meta; item->mGroup.mMeta = item->meta;
grp.mMeta = item->mGroup.mMeta; grp.mMeta = item->mGroup.mMeta;
delete item; delete item;
groups.push_back(grp); groups.push_back(grp);
} }
else
{
std::cerr << "Not a GxsForumGrpItem, deleting!" << std::endl;
delete *vit;
}
}
} }
return ok; return ok;
} }

View File

@ -397,7 +397,6 @@ bool p3IdService::getReputation(const RsGxsId &id, GixsReputation &rep)
bool p3IdService::getGroupData(const uint32_t &token, std::vector<RsGxsIdGroup> &groups) bool p3IdService::getGroupData(const uint32_t &token, std::vector<RsGxsIdGroup> &groups)
{ {
std::vector<RsGxsGrpItem*> grpData; std::vector<RsGxsGrpItem*> grpData;
bool ok = RsGenExchange::getGroupData(token, grpData); bool ok = RsGenExchange::getGroupData(token, grpData);
@ -408,6 +407,8 @@ bool p3IdService::getGroupData(const uint32_t &token, std::vector<RsGxsIdGroup>
for(; vit != grpData.end(); vit++) for(; vit != grpData.end(); vit++)
{ {
RsGxsIdGroupItem* item = dynamic_cast<RsGxsIdGroupItem*>(*vit); RsGxsIdGroupItem* item = dynamic_cast<RsGxsIdGroupItem*>(*vit);
if (item)
{
RsGxsIdGroup group = item->group; RsGxsIdGroup group = item->group;
group.mMeta = item->meta; group.mMeta = item->meta;
@ -436,14 +437,19 @@ bool p3IdService::getGroupData(const uint32_t &token, std::vector<RsGxsIdGroup>
} }
groups.push_back(group); groups.push_back(group);
delete(item);
}
else
{
std::cerr << "Not a Id Item, deleting!" << std::endl;
delete(*vit);
}
} }
delete *vit ;
} }
return ok; return ok;
} }
bool p3IdService::getMsgData(const uint32_t &token, std::vector<RsGxsIdOpinion> &opinions) bool p3IdService::getMsgData(const uint32_t &token, std::vector<RsGxsIdOpinion> &opinions)
{ {
GxsMsgDataMap msgData; GxsMsgDataMap msgData;

View File

@ -207,18 +207,25 @@ bool p3PhotoService::getAlbum(const uint32_t& token, std::vector<RsPhotoAlbum>&
for(; vit != grpData.end(); vit++) for(; vit != grpData.end(); vit++)
{ {
RsGxsPhotoAlbumItem* item = dynamic_cast<RsGxsPhotoAlbumItem*>(*vit); RsGxsPhotoAlbumItem* item = dynamic_cast<RsGxsPhotoAlbumItem*>(*vit);
if (item)
{
RsPhotoAlbum album = item->album; RsPhotoAlbum album = item->album;
item->album.mMeta = item->meta; item->album.mMeta = item->meta;
album.mMeta = item->album.mMeta; album.mMeta = item->album.mMeta;
delete item; delete item;
albums.push_back(album); albums.push_back(album);
} }
else
{
std::cerr << "Not a RsGxsPhotoAlbumItem, deleting!" << std::endl;
delete *vit;
}
}
} }
return ok; return ok;
} }
bool p3PhotoService::getPhoto(const uint32_t& token, PhotoResult& photos) bool p3PhotoService::getPhoto(const uint32_t& token, PhotoResult& photos)
{ {
GxsMsgDataMap msgData; GxsMsgDataMap msgData;

View File

@ -179,12 +179,20 @@ bool p3Posted::getGroupData(const uint32_t &token, std::vector<RsPostedGroup> &g
for(; vit != grpData.end(); vit++) for(; vit != grpData.end(); vit++)
{ {
RsGxsPostedGroupItem* item = dynamic_cast<RsGxsPostedGroupItem*>(*vit); RsGxsPostedGroupItem* item = dynamic_cast<RsGxsPostedGroupItem*>(*vit);
if (item)
{
RsPostedGroup grp = item->mGroup; RsPostedGroup grp = item->mGroup;
item->mGroup.mMeta = item->meta; item->mGroup.mMeta = item->meta;
grp.mMeta = item->mGroup.mMeta; grp.mMeta = item->mGroup.mMeta;
delete item; delete item;
groups.push_back(grp); groups.push_back(grp);
} }
else
{
std::cerr << "Not a RsGxsPostedGroupItem, deleting!" << std::endl;
delete *vit;
}
}
} }
return ok; return ok;
} }