- fixed some possible crashs with dynamic_cast
- fixed memory leak in p3GxsCircles::cache_load_for_token and p3Posted::background_loadMsgs

git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@6532 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
thunder2 2013-07-23 01:31:36 +00:00
parent fef4a87c7c
commit c3303a1969
3 changed files with 55 additions and 38 deletions

View File

@ -840,6 +840,12 @@ bool p3GxsCircles::cache_load_for_token(uint32_t token)
for(; vit != grpData.end(); vit++)
{
RsGxsCircleGroupItem *item = dynamic_cast<RsGxsCircleGroupItem*>(*vit);
if (!item)
{
std::cerr << "Not a RsGxsCircleGroupItem Item, deleting!" << std::endl;
delete(*vit);
continue;
}
RsGxsCircleGroup group;
item->convertTo(group);
@ -861,6 +867,7 @@ bool p3GxsCircles::cache_load_for_token(uint32_t token)
std::cerr << "p3GxsCircles::cache_load_for_token() Load ERROR: ";
std::cerr << item->meta;
std::cerr << std::endl;
delete(item);
// ERROR.
continue;
}

View File

@ -950,16 +950,22 @@ bool p3IdService::cache_load_for_token(uint32_t token)
std::cerr << std::endl;
#endif // DEBUG_IDS
std::vector<RsGxsGrpItem*> grpData;
bool ok = RsGenExchange::getGroupData(token, grpData);
std::vector<RsGxsGrpItem*> grpData;
bool ok = RsGenExchange::getGroupData(token, grpData);
if(ok)
{
std::vector<RsGxsGrpItem*>::iterator vit = grpData.begin();
if(ok)
{
std::vector<RsGxsGrpItem*>::iterator vit = grpData.begin();
for(; vit != grpData.end(); vit++)
{
RsGxsIdGroupItem* item = dynamic_cast<RsGxsIdGroupItem*>(*vit);
for(; vit != grpData.end(); vit++)
{
RsGxsIdGroupItem* item = dynamic_cast<RsGxsIdGroupItem*>(*vit);
if (!item)
{
std::cerr << "Not a RsGxsIdGroupItem Item, deleting!" << std::endl;
delete(*vit);
continue;
}
#ifdef DEBUG_IDS
std::cerr << "p3IdService::cache_load_for_token() Loaded Id with Meta: ";
@ -970,8 +976,8 @@ bool p3IdService::cache_load_for_token(uint32_t token)
/* cache the data */
cache_store(item);
delete item;
}
}
}
}
else
{
std::cerr << "p3IdService::cache_load_for_token() ERROR no data";
@ -982,8 +988,6 @@ bool p3IdService::cache_load_for_token(uint32_t token)
return true;
}
bool p3IdService::cache_update_if_cached(const RsGxsId &id, std::string serviceString)
{
/* if these entries are cached - update with new info */
@ -1055,45 +1059,50 @@ bool p3IdService::cache_load_ownids(uint32_t token)
std::cerr << std::endl;
#endif // DEBUG_IDS
std::vector<RsGxsGrpItem*> grpData;
bool ok = RsGenExchange::getGroupData(token, grpData);
std::vector<RsGxsGrpItem*> grpData;
bool ok = RsGenExchange::getGroupData(token, grpData);
if(ok)
{
std::vector<RsGxsGrpItem*>::iterator vit = grpData.begin();
if(ok)
{
std::vector<RsGxsGrpItem*>::iterator vit = grpData.begin();
// Save List
// Save List
{
RsStackMutex stack(mIdMtx); /********** STACK LOCKED MTX ******/
mOwnIds.clear();
for(vit = grpData.begin(); vit != grpData.end(); vit++)
{
RsGxsIdGroupItem* item = dynamic_cast<RsGxsIdGroupItem*>(*vit);
for(vit = grpData.begin(); vit != grpData.end(); vit++)
{
RsGxsIdGroupItem* item = dynamic_cast<RsGxsIdGroupItem*>(*vit);
if (!item)
{
std::cerr << "Not a IdOpinion Item, deleting!" << std::endl;
delete(*vit);
continue;
}
if (item->meta.mSubscribeFlags & GXS_SERV::GROUP_SUBSCRIBE_ADMIN)
{
mOwnIds.push_back(item->meta.mGroupId);
}
delete item ;
}
mOwnIds.push_back(item->meta.mGroupId);
}
delete item ;
}
}
// No need to cache these items...
// as it just causes the cache to be flushed.
// No need to cache these items...
// as it just causes the cache to be flushed.
#if 0
// Cache Items too.
for(vit = grpData.begin(); vit != grpData.end(); vit++)
{
for(vit = grpData.begin(); vit != grpData.end(); vit++)
{
RsGxsIdGroupItem* item = dynamic_cast<RsGxsIdGroupItem*>(*vit);
if (item->meta.mSubscribeFlags & GXS_SERV::GROUP_SUBSCRIBE_ADMIN)
{
std::cerr << "p3IdService::cache_load_ownids() Loaded Id with Meta: ";
std::cerr << item->meta;
std::cerr << std::endl;
/* cache the data */
cache_store(item);
}
@ -1101,7 +1110,7 @@ bool p3IdService::cache_load_ownids(uint32_t token)
}
#endif
}
}
else
{
std::cerr << "p3IdService::cache_load_ownids() ERROR no data";
@ -1112,7 +1121,6 @@ bool p3IdService::cache_load_ownids(uint32_t token)
return true;
}
/************************************************************************************/
/************************************************************************************/
@ -1565,16 +1573,16 @@ bool p3IdService::pgphash_handlerequest(uint32_t token)
std::vector<RsGxsIdGroup> groupsToProcess;
bool ok = getGroupData(token, groups);
if(ok)
{
if(ok)
{
#ifdef DEBUG_IDS
std::cerr << "p3IdService::pgphash_request() Have " << groups.size() << " Groups";
std::cerr << std::endl;
#endif // DEBUG_IDS
std::vector<RsGxsIdGroup>::iterator vit;
for(vit = groups.begin(); vit != groups.end(); vit++)
{
for(vit = groups.begin(); vit != groups.end(); vit++)
{
#ifdef DEBUG_IDS
std::cerr << "p3IdService::pgphash_request() Group Id: " << vit->mMeta.mGroupId;
std::cerr << std::endl;

View File

@ -902,6 +902,7 @@ void p3Posted::background_loadMsgs(const uint32_t &token, bool unprocessed)
std::cerr << std::endl;
std::cerr << "p3Posted::background_loadMsgs() ERROR This should not happen";
std::cerr << std::endl;
delete(*vit);
continue;
}
}
@ -999,6 +1000,7 @@ void p3Posted::background_loadMsgs(const uint32_t &token, bool unprocessed)
RsGxsGrpMsgIdPair msgId = std::make_pair(groupId, (*vit)->meta.mMsgId);
RsGenExchange::setMsgStatusFlags(token_a, msgId, 0, GXS_SERV::GXS_MSG_STATUS_UNPROCESSED);
}
delete(*vit);
}
}