Updated GXS tests, lots of mem leak fixes from valgrind run.

- mem leak caused by not deleting stored msgs and groups, rsdatastore now a group/msg sink
- mem leak caused in rsgxsnetservice by not deleting meta information after retrieval 
- fixed mem leak in rstlvkeyset::getTlv due to tlvbindata making own data copy



git-svn-id: http://svn.code.sf.net/p/retroshare/code/branches/v0.5-gxs-b1@5616 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
chrisparker126 2012-09-27 21:42:00 +00:00
parent 0fc3a2704b
commit bdd6c6041b
9 changed files with 101 additions and 47 deletions

View File

@ -508,7 +508,19 @@ int RsDataService::storeMessage(std::map<RsNxsMsg *, RsGxsMsgMetaData *> &msg)
}
// finish transaction
return mDb->execSQL("COMMIT;");
bool ret = mDb->execSQL("COMMIT;");
for(mit = msg.begin(); mit != msg.end(); mit++)
{
//TODO: API encourages aliasing, remove this abomination
if(mit->second != mit->first->metaData)
delete mit->second;
delete mit->first;
;
}
return ret;
}
@ -519,7 +531,8 @@ int RsDataService::storeGroup(std::map<RsNxsGrp *, RsGxsGrpMetaData *> &grp)
// begin transaction
mDb->execSQL("BEGIN;");
for(; sit != grp.end(); sit++){
for(; sit != grp.end(); sit++)
{
RsNxsGrp* grpPtr = sit->first;
RsGxsGrpMetaData* grpMetaPtr = sit->second;
@ -589,7 +602,18 @@ int RsDataService::storeGroup(std::map<RsNxsGrp *, RsGxsGrpMetaData *> &grp)
mDb->sqlInsert(GRP_TABLE_NAME, "", cv);
}
// finish transaction
return mDb->execSQL("COMMIT;");
bool ret = mDb->execSQL("COMMIT;");
for(sit = grp.begin(); sit != grp.end(); sit++)
{
//TODO: API encourages aliasing, remove this abomination
if(sit->second != sit->first->metaData)
delete sit->second;
delete sit->first;
}
return ret;
}
int RsDataService::retrieveNxsGrps(std::map<std::string, RsNxsGrp *> &grp, bool withMeta, bool cache){

View File

@ -564,8 +564,9 @@ void RsGenExchange::publishMsgs()
msg->metaData->serialise(metaDataBuff, &size);
msg->meta.setBinData(metaDataBuff, size);
ok = createMessage(msg);
ok = createMessage(msg);
RsGxsMessageId msgId;
RsGxsGroupId grpId;
if(ok)
{
msg->metaData->mPublishTs = time(NULL);
@ -581,12 +582,13 @@ void RsGenExchange::publishMsgs()
{
msg->metaData->mOrigMsgId = msg->metaData->mMsgId;
}
msgId = msg->msgId;
grpId = msg->grpId;
ok = mDataAccess->addMsgData(msg);
}
// add to published to allow acknowledgement
mMsgNotify.insert(std::make_pair(mit->first, std::make_pair(msg->grpId, msg->msgId)));
mMsgNotify.insert(std::make_pair(mit->first, std::make_pair(grpId, msgId)));
mDataAccess->updatePublicRequestStatus(mit->first, RsTokenServiceV2::GXS_REQUEST_V2_STATUS_COMPLETE);
}
@ -597,7 +599,7 @@ void RsGenExchange::publishMsgs()
std::cerr << "RsGenExchange::publishMsgs() failed to publish msg " << std::endl;
#endif
mMsgNotify.insert(std::make_pair(mit->first, std::make_pair(RsGxsGroupId(""), RsGxsMessageId(""))));
delete msg;
continue;
}
@ -640,11 +642,11 @@ void RsGenExchange::publishGrps()
grp->metaData->mGroupId = grp->grpId;
ok = grp->metaData->serialise(mData, size);
grp->meta.setBinData(mData, size);
ok = mDataAccess->addGroupData(grp);
RsGxsGroupId grpId = grp->grpId;
mDataAccess->addGroupData(grp);
// add to published to allow acknowledgement
mGrpNotify.insert(std::make_pair(mit->first, grp->grpId));
mGrpNotify.insert(std::make_pair(mit->first, grpId));
mDataAccess->updatePublicRequestStatus(mit->first, RsTokenServiceV2::GXS_REQUEST_V2_STATUS_COMPLETE);
}
@ -695,7 +697,7 @@ void RsGenExchange::createDummyGroup(RsGxsGrpItem *grpItem)
ok = grp->metaData->serialise(mData, size);
grp->meta.setBinData(mData, size);
ok = mDataAccess->addGroupData(grp);
mDataAccess->addGroupData(grp);
}
if(!ok)

View File

@ -100,6 +100,8 @@ void RsGxsNetService::syncWithPeers()
if(meta->mSubscribeFlags & GXS_SERV::GROUP_SUBSCRIBE_SUBSCRIBED)
grpIds.push_back(mit->first);
delete meta;
}
sit = peers.begin();
@ -1131,6 +1133,7 @@ void RsGxsNetService::handleRecvSyncGroup(RsNxsSyncGrp* item)
gItem->PeerId(peer);
gItem->transactionNumber = transN;
itemL.push_back(gItem);
delete mit->second; // release resource
}
tr->mFlag = NxsTransaction::FLAG_STATE_WAITING_CONFIRM;

View File

@ -322,7 +322,7 @@ bool RsTlvSecurityKeySet::GetTlv(void *data, uint32_t size, uint32_t *offset) /
if (ok)
{
keys[key.keyId] = key;
key.ShallowClear(); /* so that the Map can get control - should be ref counted*/
key.TlvClear(); /* so that the Map can get control - should be ref counted*/
}
}
break;

View File

@ -1,6 +1,7 @@
#include "genexchangetester.h"
#include "support.h"
#include "gxs/rsdataservice.h"
#include "gxs/rsgxsflags.h"
GenExchangeTester::GenExchangeTester()
@ -1404,7 +1405,7 @@ void GenExchangeTester::init(RsGroupMetaData &grpMeta) const
grpMeta.mPop = randNum();
grpMeta.mSignFlags = randNum();
grpMeta.mPublishTs = randNum();
grpMeta.mSubscribeFlags = randNum();
grpMeta.mSubscribeFlags = GXS_SERV::GROUP_SUBSCRIBE_ADMIN;
}
@ -1510,7 +1511,7 @@ void GenExchangeTester::pollForToken(uint32_t token, const RsTokReqOptionsV2 &op
Sleep((int) (timeDelta * 1000));
#endif
if(RsTokenServiceV2::GXS_REQUEST_STATUS_COMPLETE ==
if(RsTokenServiceV2::GXS_REQUEST_V2_STATUS_COMPLETE ==
mTokenService->requestStatus(token))
{
switch(opts.mReqType)

View File

@ -10,7 +10,7 @@ QT += core network
QT -= gui
CONFIG += gen_exchange_target #dstore_target
CONFIG += dstore_target #gen_exchange_target # #nxs_net_test
dstore_target {
@ -24,6 +24,12 @@ TARGET = gen_exchange_test
}
nxs_net_test {
TARGET = nxs_net_test
}
CONFIG += console
CONFIG -= app_bundle
@ -187,4 +193,21 @@ gen_exchange_target {
}
nxs_net_test {
SOURCES += \
support.cc \
nxstesthub.cc \
rsgxsnetservice_test.cc \
nxstestscenario.cc \
data_support.cc
HEADERS += support.h \
nxstesthub.h \
rsgxsnetservice_test.h \
nxstestscenario.h \
data_support.h
}
INCLUDEPATH += ../../

View File

@ -82,16 +82,6 @@ void NxsMessageTest::populateStore(RsGeneralDataService* dStore)
dStore->storeGroup(grps);
std::map<RsNxsGrp*, RsGxsGrpMetaData*>::iterator grp_it
= grps.begin();
for(; grp_it != grps.end(); grp_it++)
{
delete grp_it->first;
delete grp_it->second;
}
int nMsgs = rand()%23;
std::map<RsNxsMsg*, RsGxsMsgMetaData*> msgs;
RsNxsMsg* msg = NULL;
@ -119,16 +109,6 @@ void NxsMessageTest::populateStore(RsGeneralDataService* dStore)
dStore->storeMessage(msgs);
// clean up
std::map<RsNxsMsg*, RsGxsMsgMetaData*>::iterator msg_it
= msgs.begin();
for(; msg_it != msgs.end(); msg_it++)
{
delete msg_it->first;
delete msg_it->second;
}
return;
}

View File

@ -38,7 +38,7 @@ void test_groupStoreAndRetrieve(){
setUp();
int nGrp = rand()%32;
std::map<RsNxsGrp*, RsGxsGrpMetaData*> grps;
std::map<RsNxsGrp*, RsGxsGrpMetaData*> grps, grps_copy;
RsNxsGrp* grp;
RsGxsGrpMetaData* grpMeta;
for(int i = 0; i < nGrp; i++){
@ -51,13 +51,21 @@ void test_groupStoreAndRetrieve(){
init_item(grpMeta);
grpMeta->mGroupId = grp->grpId;
grps.insert(p);
RsNxsGrp* grp_copy = new RsNxsGrp(RS_SERVICE_TYPE_PLUGIN_SIMPLE_FORUM);
*grp_copy = *grp;
RsGxsGrpMetaData* grpMeta_copy = new RsGxsGrpMetaData();
*grpMeta_copy = *grpMeta;
grps_copy.insert(std::make_pair(grp_copy, grpMeta_copy ));
grpMeta = NULL;
grp = NULL;
}
dStore->storeGroup(grps);
//use copy, a grps are deleted in store
grps.clear();
grps = grps_copy;
std::map<RsGxsGroupId, RsNxsGrp*> gR;
std::map<RsGxsGroupId, RsGxsGrpMetaData*> grpMetaR;
dStore->retrieveNxsGrps(gR, false, false);
@ -141,6 +149,7 @@ void test_messageStoresAndRetrieve()
grpV.push_back(grpId1);
std::map<RsNxsMsg*, RsGxsMsgMetaData*> msgs;
std::map<RsNxsMsg*, RsGxsMsgMetaData*> msgs_copy;
RsNxsMsg* msg = NULL;
RsGxsMsgMetaData* msgMeta = NULL;
int nMsgs = rand()%120;
@ -170,9 +179,15 @@ void test_messageStoresAndRetrieve()
msgMeta->mMsgId = msg->msgId;
msgMeta->mGroupId = msg->grpId = grpId;
RsNxsMsg* msg_copy = new RsNxsMsg(RS_SERVICE_TYPE_PLUGIN_SIMPLE_FORUM);
RsGxsMsgMetaData* msgMeta_copy = new RsGxsMsgMetaData();
*msg_copy = *msg;
*msgMeta_copy = *msgMeta;
// store msgs in map to use for verification
std::pair<std::string, RsNxsMsg*> vP(msg->msgId, msg);
std::pair<std::string, RsGxsMsgMetaData*> vPmeta(msg->msgId, msgMeta);
std::pair<std::string, RsNxsMsg*> vP(msg->msgId, msg_copy);
std::pair<std::string, RsGxsMsgMetaData*> vPmeta(msg->msgId, msgMeta_copy);
if(!chosen)
{
@ -184,15 +199,21 @@ void test_messageStoresAndRetrieve()
VergrpId1.insert(vP);
VerMetagrpId0.insert(vPmeta);
}
msg = NULL;
msgMeta = NULL;
msgs.insert(p);
msgs_copy.insert(std::make_pair(msg_copy, msgMeta_copy));
}
req[grpV[0]] = std::vector<RsGxsMessageId>(); // assign empty list for other
dStore->storeMessage(msgs);
msgs.clear();
msgs = msgs_copy;
// now retrieve msgs for comparison
// first selective retrieval

View File

@ -17,16 +17,16 @@ int main()
// CHECK(tester.testMsgSubmissionRetrieval()); REPORT("testMsgSubmissionRetrieval()");
// CHECK(tester.testSpecificMsgMetaRetrieval()); REPORT("testSpecificMsgMetaRetrieval()");
// CHECK(tester.testMsgIdRetrieval()); REPORT("tester.testMsgIdRetrieval()");
//CHECK(tester.testMsgIdRetrieval_OptParents()); REPORT("tester.testRelatedMsgIdRetrieval_Parents()");
// CHECK(tester.testMsgIdRetrieval_OptParents()); REPORT("tester.testRelatedMsgIdRetrieval_Parents()");
// CHECK(tester.testMsgIdRetrieval_OptOrigMsgId()); REPORT("tester.testRelatedMsgIdRetrieval_OrigMsgId()");
// CHECK(tester.testMsgIdRetrieval_OptLatest()); REPORT("tester.testRelatedMsgIdRetrieval_Latest()");
//CHECK(tester.testMsgMetaModRequest()); REPORT("tester.testMsgMetaModRequest()");
CHECK(tester.testMsgChildRetrieval()); REPORT("tester.testMsgMetaModRequest()");
// CHECK(tester.testMsgMetaModRequest()); REPORT("tester.testMsgMetaModRequest()");
// CHECK(tester.testMsgChildRetrieval()); REPORT("tester.testMsgMetaModRequest()");
// CHECK(tester.testGrpSubmissionRetrieval()); REPORT("tester.testGrpSubmissionRetrieval()");
// CHECK(tester.testGrpMetaRetrieval()); REPORT("tester.testGrpMetaRetrieval()");
// CHECK(tester.testGrpIdRetrieval()); REPORT("tester.testGrpIdRetrieval()");
// CHECK(tester.testGrpMetaModRequest()); REPORT("tester.testGrpMetaModRequest()");
CHECK(tester.testGrpSubmissionRetrieval()); REPORT("tester.testGrpSubmissionRetrieval()");
CHECK(tester.testGrpMetaRetrieval()); REPORT("tester.testGrpMetaRetrieval()");
CHECK(tester.testGrpIdRetrieval()); REPORT("tester.testGrpIdRetrieval()");
CHECK(tester.testGrpMetaModRequest()); REPORT("tester.testGrpMetaModRequest()");
FINALREPORT("RsGenExchangeTest");