From 461ccf3b84dfe257eeda51206d7832ce877a9ae2 Mon Sep 17 00:00:00 2001 From: csoler Date: Tue, 25 Jul 2017 00:07:53 +0200 Subject: [PATCH] removed aliasing in storeMessages/storeGroups, removed several memory leaks in unittests, improved auto-delete structures in rsgxsutil, added deletion for members of RsGenExchange, removed shared pointers from unittests (they cause a memory leak and are only used in unittests) --- libretroshare/src/gxs/rsdataservice.cc | 183 ++++++++---------- libretroshare/src/gxs/rsdataservice.h | 6 +- libretroshare/src/gxs/rsgds.h | 6 +- libretroshare/src/gxs/rsgenexchange.cc | 73 +++---- libretroshare/src/gxs/rsgenexchange.h | 2 +- libretroshare/src/gxs/rsgxsdataaccess.cc | 17 +- libretroshare/src/gxs/rsgxsdataaccess.h | 2 +- libretroshare/src/gxs/rsgxsnetservice.h | 5 +- libretroshare/src/gxs/rsgxsutil.h | 50 +++-- libretroshare/src/util/rssharedptr.h | 1 + .../gxs/data_service/rsdataservice_test.cc | 78 +++----- .../gen_exchange/genexchangetestservice.cc | 9 +- .../gxs/gen_exchange/genexchangetestservice.h | 2 + .../gxs/gen_exchange/rsgenexchange_test.cc | 4 + .../gxs/nxs_test/nxsgrpsync_test.cc | 4 +- .../gxs/nxs_test/nxsmsgsync_test.cc | 24 ++- .../gxs/nxs_test/nxsmsgsync_test.h | 1 + .../libretroshare/gxs/nxs_test/nxstesthub.cc | 63 +++--- .../libretroshare/gxs/nxs_test/nxstesthub.h | 12 +- .../gxs/nxs_test/rsgxsnetservice_test.cc | 12 +- .../serialiser/rsmsgitem_test.cc | 2 +- 21 files changed, 281 insertions(+), 275 deletions(-) diff --git a/libretroshare/src/gxs/rsdataservice.cc b/libretroshare/src/gxs/rsdataservice.cc index 8486e95d0..535aa3035 100644 --- a/libretroshare/src/gxs/rsdataservice.cc +++ b/libretroshare/src/gxs/rsdataservice.cc @@ -702,20 +702,20 @@ RsNxsMsg* RsDataService::locked_getMessage(RetroCursor &c) return NULL; } -int RsDataService::storeMessage(std::map &msg) +int RsDataService::storeMessage(const std::list& msg) { RsStackMutex stack(mDbMutex); - std::map::iterator mit = msg.begin(); - // start a transaction mDb->beginTransaction(); - for(; mit != msg.end(); ++mit) + for(std::list::const_iterator mit = msg.begin(); mit != msg.end(); ++mit) { - RsNxsMsg* msgPtr = mit->first; - RsGxsMsgMetaData* msgMetaPtr = mit->second; + RsNxsMsg* msgPtr = *mit; + RsGxsMsgMetaData* msgMetaPtr = msgPtr->metaData; + + assert(msgMetaPtr != NULL); #ifdef RS_DATA_SERVICE_DEBUG std::cerr << "RsDataService::storeMessage() "; @@ -790,16 +790,6 @@ int RsDataService::storeMessage(std::map &msg) // finish transaction bool ret = mDb->commitTransaction(); - 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; } @@ -811,104 +801,94 @@ bool RsDataService::validSize(RsNxsMsg* msg) const } -int RsDataService::storeGroup(std::map &grp) +int RsDataService::storeGroup(const std::list& grp) { RsStackMutex stack(mDbMutex); - std::map::iterator sit = grp.begin(); - // begin transaction mDb->beginTransaction(); - for(; sit != grp.end(); ++sit) - { + for(std::list::const_iterator sit = grp.begin();sit != grp.end(); ++sit) + { + RsNxsGrp* grpPtr = *sit; + RsGxsGrpMetaData* grpMetaPtr = grpPtr->metaData; - RsNxsGrp* grpPtr = sit->first; - RsGxsGrpMetaData* grpMetaPtr = sit->second; + assert(grpMetaPtr != NULL); - // if data is larger than max item size do not add - if(!validSize(grpPtr)) continue; + // if data is larger than max item size do not add + if(!validSize(grpPtr)) continue; #ifdef RS_DATA_SERVICE_DEBUG - std::cerr << "RsDataService::storeGroup() GrpId: " << grpPtr->grpId.toStdString(); - std::cerr << " CircleType: " << (uint32_t) grpMetaPtr->mCircleType; - std::cerr << " CircleId: " << grpMetaPtr->mCircleId.toStdString(); - std::cerr << std::endl; + std::cerr << "RsDataService::storeGroup() GrpId: " << grpPtr->grpId.toStdString(); + std::cerr << " CircleType: " << (uint32_t) grpMetaPtr->mCircleType; + std::cerr << " CircleId: " << grpMetaPtr->mCircleId.toStdString(); + std::cerr << std::endl; #endif - /*! - * STORE data, data len, - * grpId, flags, publish time stamp, identity, - * id signature, admin signatue, key set, last posting ts - * and meta data - **/ - ContentValue cv; + /*! + * STORE data, data len, + * grpId, flags, publish time stamp, identity, + * id signature, admin signatue, key set, last posting ts + * and meta data + **/ + ContentValue cv; - uint32_t dataLen = grpPtr->grp.TlvSize(); - char grpData[dataLen]; - uint32_t offset = 0; - grpPtr->grp.SetTlv(grpData, dataLen, &offset); - cv.put(KEY_NXS_DATA, dataLen, grpData); + uint32_t dataLen = grpPtr->grp.TlvSize(); + char grpData[dataLen]; + uint32_t offset = 0; + grpPtr->grp.SetTlv(grpData, dataLen, &offset); + cv.put(KEY_NXS_DATA, dataLen, grpData); - cv.put(KEY_NXS_DATA_LEN, (int32_t) dataLen); - cv.put(KEY_GRP_ID, grpPtr->grpId.toStdString()); - cv.put(KEY_GRP_NAME, grpMetaPtr->mGroupName); - cv.put(KEY_ORIG_GRP_ID, grpMetaPtr->mOrigGrpId.toStdString()); - cv.put(KEY_NXS_SERV_STRING, grpMetaPtr->mServiceString); - cv.put(KEY_NXS_FLAGS, (int32_t)grpMetaPtr->mGroupFlags); - cv.put(KEY_TIME_STAMP, (int32_t)grpMetaPtr->mPublishTs); - cv.put(KEY_GRP_SIGN_FLAGS, (int32_t)grpMetaPtr->mSignFlags); - cv.put(KEY_GRP_CIRCLE_ID, grpMetaPtr->mCircleId.toStdString()); - cv.put(KEY_GRP_CIRCLE_TYPE, (int32_t)grpMetaPtr->mCircleType); - cv.put(KEY_GRP_INTERNAL_CIRCLE, grpMetaPtr->mInternalCircle.toStdString()); - cv.put(KEY_GRP_ORIGINATOR, grpMetaPtr->mOriginator.toStdString()); - cv.put(KEY_GRP_AUTHEN_FLAGS, (int32_t)grpMetaPtr->mAuthenFlags); - cv.put(KEY_PARENT_GRP_ID, grpMetaPtr->mParentGrpId.toStdString()); - cv.put(KEY_NXS_HASH, grpMetaPtr->mHash.toStdString()); - cv.put(KEY_RECV_TS, (int32_t)grpMetaPtr->mRecvTS); - cv.put(KEY_GRP_REP_CUTOFF, (int32_t)grpMetaPtr->mReputationCutOff); - cv.put(KEY_NXS_IDENTITY, grpMetaPtr->mAuthorId.toStdString()); + cv.put(KEY_NXS_DATA_LEN, (int32_t) dataLen); + cv.put(KEY_GRP_ID, grpPtr->grpId.toStdString()); + cv.put(KEY_GRP_NAME, grpMetaPtr->mGroupName); + cv.put(KEY_ORIG_GRP_ID, grpMetaPtr->mOrigGrpId.toStdString()); + cv.put(KEY_NXS_SERV_STRING, grpMetaPtr->mServiceString); + cv.put(KEY_NXS_FLAGS, (int32_t)grpMetaPtr->mGroupFlags); + cv.put(KEY_TIME_STAMP, (int32_t)grpMetaPtr->mPublishTs); + cv.put(KEY_GRP_SIGN_FLAGS, (int32_t)grpMetaPtr->mSignFlags); + cv.put(KEY_GRP_CIRCLE_ID, grpMetaPtr->mCircleId.toStdString()); + cv.put(KEY_GRP_CIRCLE_TYPE, (int32_t)grpMetaPtr->mCircleType); + cv.put(KEY_GRP_INTERNAL_CIRCLE, grpMetaPtr->mInternalCircle.toStdString()); + cv.put(KEY_GRP_ORIGINATOR, grpMetaPtr->mOriginator.toStdString()); + cv.put(KEY_GRP_AUTHEN_FLAGS, (int32_t)grpMetaPtr->mAuthenFlags); + cv.put(KEY_PARENT_GRP_ID, grpMetaPtr->mParentGrpId.toStdString()); + cv.put(KEY_NXS_HASH, grpMetaPtr->mHash.toStdString()); + cv.put(KEY_RECV_TS, (int32_t)grpMetaPtr->mRecvTS); + cv.put(KEY_GRP_REP_CUTOFF, (int32_t)grpMetaPtr->mReputationCutOff); + cv.put(KEY_NXS_IDENTITY, grpMetaPtr->mAuthorId.toStdString()); - offset = 0; - char keySetData[grpMetaPtr->keys.TlvSize()]; - grpMetaPtr->keys.SetTlv(keySetData, grpMetaPtr->keys.TlvSize(), &offset); - cv.put(KEY_KEY_SET, grpMetaPtr->keys.TlvSize(), keySetData); + offset = 0; + char keySetData[grpMetaPtr->keys.TlvSize()]; + grpMetaPtr->keys.SetTlv(keySetData, grpMetaPtr->keys.TlvSize(), &offset); + cv.put(KEY_KEY_SET, grpMetaPtr->keys.TlvSize(), keySetData); - offset = 0; - char metaData[grpPtr->meta.TlvSize()]; - grpPtr->meta.SetTlv(metaData, grpPtr->meta.TlvSize(), &offset); - cv.put(KEY_NXS_META, grpPtr->meta.TlvSize(), metaData); + offset = 0; + char metaData[grpPtr->meta.TlvSize()]; + grpPtr->meta.SetTlv(metaData, grpPtr->meta.TlvSize(), &offset); + cv.put(KEY_NXS_META, grpPtr->meta.TlvSize(), metaData); - // local meta data - cv.put(KEY_GRP_SUBCR_FLAG, (int32_t)grpMetaPtr->mSubscribeFlags); - cv.put(KEY_GRP_POP, (int32_t)grpMetaPtr->mPop); - cv.put(KEY_MSG_COUNT, (int32_t)grpMetaPtr->mVisibleMsgCount); - cv.put(KEY_GRP_STATUS, (int32_t)grpMetaPtr->mGroupStatus); - cv.put(KEY_GRP_LAST_POST, (int32_t)grpMetaPtr->mLastPost); + // local meta data + cv.put(KEY_GRP_SUBCR_FLAG, (int32_t)grpMetaPtr->mSubscribeFlags); + cv.put(KEY_GRP_POP, (int32_t)grpMetaPtr->mPop); + cv.put(KEY_MSG_COUNT, (int32_t)grpMetaPtr->mVisibleMsgCount); + cv.put(KEY_GRP_STATUS, (int32_t)grpMetaPtr->mGroupStatus); + cv.put(KEY_GRP_LAST_POST, (int32_t)grpMetaPtr->mLastPost); - locked_clearGrpMetaCache(grpMetaPtr->mGroupId); + locked_clearGrpMetaCache(grpMetaPtr->mGroupId); - if (!mDb->sqlInsert(GRP_TABLE_NAME, "", cv)) - { - std::cerr << "RsDataService::storeGroup() sqlInsert Failed"; - std::cerr << std::endl; - std::cerr << "\t For GroupId: " << grpMetaPtr->mGroupId.toStdString(); - std::cerr << std::endl; - } - } + if (!mDb->sqlInsert(GRP_TABLE_NAME, "", cv)) + { + std::cerr << "RsDataService::storeGroup() sqlInsert Failed"; + std::cerr << std::endl; + std::cerr << "\t For GroupId: " << grpMetaPtr->mGroupId.toStdString(); + std::cerr << std::endl; + } + } // finish transaction bool ret = mDb->commitTransaction(); - 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; } @@ -918,21 +898,21 @@ void RsDataService::locked_clearGrpMetaCache(const RsGxsGroupId& gid) mGrpMetaDataCache_ContainsAllDatabase = false; } -int RsDataService::updateGroup(std::map &grp) +int RsDataService::updateGroup(const std::list &grp) { RsStackMutex stack(mDbMutex); - std::map::iterator sit = grp.begin(); - // begin transaction mDb->beginTransaction(); - for(; sit != grp.end(); ++sit) + for( std::list::const_iterator sit = grp.begin(); sit != grp.end(); ++sit) { - RsNxsGrp* grpPtr = sit->first; - RsGxsGrpMetaData* grpMetaPtr = sit->second; + RsNxsGrp* grpPtr = *sit; + RsGxsGrpMetaData* grpMetaPtr = grpPtr->metaData; + + assert(grpMetaPtr != NULL); // if data is larger than max item size do not add if(!validSize(grpPtr)) continue; @@ -991,15 +971,6 @@ int RsDataService::updateGroup(std::map &grp) // finish transaction bool ret = mDb->commitTransaction(); - 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; } diff --git a/libretroshare/src/gxs/rsdataservice.h b/libretroshare/src/gxs/rsdataservice.h index a48da407f..1e33747d6 100644 --- a/libretroshare/src/gxs/rsdataservice.h +++ b/libretroshare/src/gxs/rsdataservice.h @@ -127,21 +127,21 @@ public: * @param msg map of message and decoded meta data information * @return error code */ - int storeMessage(std::map& msg); + int storeMessage(const std::list& msg); /*! * Stores a list of groups in data store * @param grp map of group and decoded meta data * @return error code */ - int storeGroup(std::map& grp); + int storeGroup(const std::list& grp); /*! * Updates group entries in Db * @param grp map of group and decoded meta data * @return error code */ - int updateGroup(std::map& grsp); + int updateGroup(const std::list& grsp); /*! * @param metaData The meta data item to update diff --git a/libretroshare/src/gxs/rsgds.h b/libretroshare/src/gxs/rsgds.h index 2cb153056..33ed386c4 100644 --- a/libretroshare/src/gxs/rsgds.h +++ b/libretroshare/src/gxs/rsgds.h @@ -223,14 +223,14 @@ public: * @param msg map of message and decoded meta data information * @return error code */ - virtual int storeMessage(std::map& msgs) = 0; + virtual int storeMessage(const std::list& msgs) = 0; /*! * Stores a list of groups in data store * @param grp map of group and decoded meta data * @return error code */ - virtual int storeGroup(std::map& grsp) = 0; + virtual int storeGroup(const std::list& grsp) = 0; /*! @@ -238,7 +238,7 @@ public: * @param grp map of group and decoded meta data * @return error code */ - virtual int updateGroup(std::map& grsp) = 0; + virtual int updateGroup(const std::list& grsp) = 0; /*! * @param metaData diff --git a/libretroshare/src/gxs/rsgenexchange.cc b/libretroshare/src/gxs/rsgenexchange.cc index dd87cc10b..5be6fd3f1 100644 --- a/libretroshare/src/gxs/rsgenexchange.cc +++ b/libretroshare/src/gxs/rsgenexchange.cc @@ -117,6 +117,14 @@ RsGenExchange::~RsGenExchange() delete mDataStore; mDataStore = NULL; + for(uint32_t i=0;imsg, msg->metaData->mHash); mDataAccess->addMsgData(msg); + delete msg ; + msgChangeMap[grpId].push_back(msgId); delete[] metaDataBuff; @@ -2664,9 +2674,9 @@ void RsGenExchange::publishGrps() mDataAccess->updateGroupData(grp); else mDataAccess->addGroupData(grp); -#warning csoler: this is bad: addGroupData/updateGroupData actially deletes grp. But it may be used below? grp should be a class object and not deleted manually! - groups_to_subscribe.push_back(grpId) ; + delete grp ; + groups_to_subscribe.push_back(grpId) ; } else { @@ -2885,9 +2895,8 @@ void RsGenExchange::processRecvdMessages() std::vector::iterator vit = mReceivedMsgs.begin(); GxsMsgReq msgIds; - std::map msgs; - - std::map grpMetas; + RsNxsMsgDataTemporaryList msgs; + RsGxsGrpMetaTemporaryMap grpMetas; // coalesce group meta retrieval for performance for(; vit != mReceivedMsgs.end(); ++vit) @@ -2961,7 +2970,7 @@ void RsGenExchange::processRecvdMessages() if(validateReturn == VALIDATE_SUCCESS) { meta->mMsgStatus = GXS_SERV::GXS_MSG_STATUS_UNPROCESSED | GXS_SERV::GXS_MSG_STATUS_GUI_NEW | GXS_SERV::GXS_MSG_STATUS_GUI_UNREAD; - msgs.insert(std::make_pair(msg, meta)); + msgs.push_back(msg); std::vector &msgv = msgIds[msg->grpId]; if (std::find(msgv.begin(), msgv.end(), msg->msgId) == msgv.end()) @@ -3038,15 +3047,9 @@ void RsGenExchange::processRecvdMessages() if(vit == mMsgPendingValidate.end()) mMsgPendingValidate.push_back(GxsPendingItem(msg, id,time(NULL))); -// else -// delete msg ; } } - // clean up resources from group meta retrieval - freeAndClearContainerResource, - RsGxsGrpMetaData*>(grpMetas); - if(!msgIds.empty()) { #ifdef GEN_EXCH_DEBUG @@ -3091,7 +3094,7 @@ void RsGenExchange::processRecvdGroups() std::vector existingGrpIds; std::list grpIds; - std::map grps; + RsNxsGrpDataTemporaryList grps; mDataStore->retrieveGroupIds(existingGrpIds); @@ -3145,7 +3148,7 @@ void RsGenExchange::processRecvdGroups() meta->mSubscribeFlags = GXS_SERV::GROUP_SUBSCRIBE_NOT_SUBSCRIBED; - grps.insert(std::make_pair(grp, meta)); + grps.push_back(grp); grpIds.push_back(grp->grpId); } else @@ -3250,7 +3253,9 @@ void RsGenExchange::performUpdateValidation() #endif vit = mGroupUpdates.begin(); - std::map grps; + + RsNxsGrpDataTemporaryList grps ; + for(; vit != mGroupUpdates.end(); ++vit) { GroupUpdate& gu = *vit; @@ -3265,7 +3270,7 @@ void RsGenExchange::performUpdateValidation() gu.newGrp->metaData->mSubscribeFlags = gu.oldGrpMeta->mSubscribeFlags ; - grps.insert(std::make_pair(gu.newGrp, gu.newGrp->metaData)); + grps.push_back(gu.newGrp); } else { @@ -3353,14 +3358,14 @@ void RsGenExchange::setGroupReputationCutOff(uint32_t& token, const RsGxsGroupId mGrpLocMetaMap.insert(std::make_pair(token, g)); } -void RsGenExchange::removeDeleteExistingMessages( RsGeneralDataService::MsgStoreMap& msgs, GxsMsgReq& msgIdsNotify) +void RsGenExchange::removeDeleteExistingMessages( std::list& msgs, GxsMsgReq& msgIdsNotify) { // first get grp ids of messages to be stored RsGxsGroupId::std_set mGrpIdsUnique; - for(RsGeneralDataService::MsgStoreMap::const_iterator cit = msgs.begin(); cit != msgs.end(); ++cit) - mGrpIdsUnique.insert(cit->second->mGroupId); + for(std::list::const_iterator cit = msgs.begin(); cit != msgs.end(); ++cit) + mGrpIdsUnique.insert((*cit)->metaData->mGroupId); //RsGxsGroupId::std_list grpIds(mGrpIdsUnique.begin(), mGrpIdsUnique.end()); //RsGxsGroupId::std_list::const_iterator it = grpIds.begin(); @@ -3381,13 +3386,10 @@ void RsGenExchange::removeDeleteExistingMessages( RsGeneralDataService::MsgStore #endif } - //RsGeneralDataService::MsgStoreMap::iterator cit2 = msgs.begin(); - RsGeneralDataService::MsgStoreMap filtered; - // now for each msg to be stored that exist in the retrieved msg/grp "index" delete and erase from map - for(RsGeneralDataService::MsgStoreMap::iterator cit2 = msgs.begin(); cit2 != msgs.end(); ++cit2) + for(std::list::iterator cit2 = msgs.begin(); cit2 != msgs.end(); ++cit2) { - const RsGxsMessageId::std_vector& msgIds = msgIdReq[cit2->second->mGroupId]; + const RsGxsMessageId::std_vector& msgIds = msgIdReq[(*cit2)->metaData->mGroupId]; #ifdef GEN_EXCH_DEBUG std::cerr << " grpid=" << cit2->second->mGroupId << ", msgid=" << cit2->second->mMsgId ; @@ -3395,38 +3397,27 @@ void RsGenExchange::removeDeleteExistingMessages( RsGeneralDataService::MsgStore // Avoid storing messages that are already in the database, as well as messages that are too old (or generally do not pass the database storage test) // - if(std::find(msgIds.begin(), msgIds.end(), cit2->second->mMsgId) == msgIds.end() && messagePublicationTest(*cit2->second)) - { - // passes tests, so add to filtered list - // - filtered.insert(*cit2); -#ifdef GEN_EXCH_DEBUG - std::cerr << " keeping " << cit2->second->mMsgId << std::endl; -#endif - } - else // remove message from list + if(std::find(msgIds.begin(), msgIds.end(), (*cit2)->metaData->mMsgId) != msgIds.end() || !messagePublicationTest( *(*cit2)->metaData)) { // msg exist in retrieved index - RsGxsMessageId::std_vector& notifyIds = msgIdsNotify[cit2->second->mGroupId]; - RsGxsMessageId::std_vector::iterator it2 = std::find(notifyIds.begin(), - notifyIds.end(), cit2->second->mMsgId); + 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()) { notifyIds.erase(it2); if (notifyIds.empty()) { - msgIdsNotify.erase(cit2->second->mGroupId); + msgIdsNotify.erase( (*cit2)->metaData->mGroupId); } } #ifdef GEN_EXCH_DEBUG std::cerr << " discarding " << cit2->second->mMsgId << std::endl; #endif - delete cit2->first; + delete *cit2; + msgs.erase(cit2); // cit2->second will be deleted too in the destructor of cit2->first (RsNxsMsg) } } - - msgs = filtered; } diff --git a/libretroshare/src/gxs/rsgenexchange.h b/libretroshare/src/gxs/rsgenexchange.h index 093b342c9..78151cdae 100644 --- a/libretroshare/src/gxs/rsgenexchange.h +++ b/libretroshare/src/gxs/rsgenexchange.h @@ -850,7 +850,7 @@ private: * @param msgs messages to be filtered * @param msgIdsNotify message notification map to be filtered */ - void removeDeleteExistingMessages(RsGeneralDataService::MsgStoreMap& msgs, GxsMsgReq& msgIdsNotify); + void removeDeleteExistingMessages(std::list& msgs, GxsMsgReq& msgIdsNotify); RsMutex mGenMtx; RsGxsDataAccess* mDataAccess; diff --git a/libretroshare/src/gxs/rsgxsdataaccess.cc b/libretroshare/src/gxs/rsgxsdataaccess.cc index 8529b89f4..e010ffaf9 100644 --- a/libretroshare/src/gxs/rsgxsdataaccess.cc +++ b/libretroshare/src/gxs/rsgxsdataaccess.cc @@ -45,6 +45,11 @@ RsGxsDataAccess::RsGxsDataAccess(RsGeneralDataService* ds) : mDataStore(ds), mDataMutex("RsGxsDataAccess"), mNextToken(0) {} +RsGxsDataAccess::~RsGxsDataAccess() +{ + for(std::map::const_iterator it(mRequests.begin());it!=mRequests.end();++it) + delete it->second ; +} bool RsGxsDataAccess::requestGroupInfo(uint32_t &token, uint32_t ansType, const RsTokReqOptions &opts, const std::list &groupIds) { @@ -1803,8 +1808,8 @@ bool RsGxsDataAccess::addGroupData(RsNxsGrp* grp) { RsStackMutex stack(mDataMutex); - std::map grpM; - grpM.insert(std::make_pair(grp, grp->metaData)); + std::list grpM; + grpM.push_back(grp); return mDataStore->storeGroup(grpM); } @@ -1812,8 +1817,8 @@ bool RsGxsDataAccess::updateGroupData(RsNxsGrp* grp) { RsStackMutex stack(mDataMutex); - std::map grpM; - grpM.insert(std::make_pair(grp, grp->metaData)); + std::list grpM; + grpM.push_back(grp); return mDataStore->updateGroup(grpM); } @@ -1821,8 +1826,8 @@ bool RsGxsDataAccess::addMsgData(RsNxsMsg* msg) { RsStackMutex stack(mDataMutex); - std::map msgM; - msgM.insert(std::make_pair(msg, msg->metaData)); + std::list msgM; + msgM.push_back(msg); return mDataStore->storeMessage(msgM); } diff --git a/libretroshare/src/gxs/rsgxsdataaccess.h b/libretroshare/src/gxs/rsgxsdataaccess.h index d39823f81..04a785286 100644 --- a/libretroshare/src/gxs/rsgxsdataaccess.h +++ b/libretroshare/src/gxs/rsgxsdataaccess.h @@ -38,7 +38,7 @@ class RsGxsDataAccess : public RsTokenService { public: RsGxsDataAccess(RsGeneralDataService* ds); - virtual ~RsGxsDataAccess() { return ;} + virtual ~RsGxsDataAccess() ; public: diff --git a/libretroshare/src/gxs/rsgxsnetservice.h b/libretroshare/src/gxs/rsgxsnetservice.h index 369b88380..29c28e96e 100644 --- a/libretroshare/src/gxs/rsgxsnetservice.h +++ b/libretroshare/src/gxs/rsgxsnetservice.h @@ -71,13 +71,10 @@ class RsGroupNetworkStatsRecord * Incoming transaction are in 3 different states * 1. START 2. RECEIVING 3. END */ -class RsGxsNetService : public RsNetworkExchangeService, public p3ThreadedService, - public p3Config +class RsGxsNetService : public RsNetworkExchangeService, public p3ThreadedService, public p3Config { public: - typedef RsSharedPtr pointer; - static const uint32_t FRAGMENT_SIZE; /*! * only one observer is allowed diff --git a/libretroshare/src/gxs/rsgxsutil.h b/libretroshare/src/gxs/rsgxsutil.h index f55c7c147..a83d768ba 100644 --- a/libretroshare/src/gxs/rsgxsutil.h +++ b/libretroshare/src/gxs/rsgxsutil.h @@ -33,26 +33,19 @@ class RsGixs ; class RsGenExchange ; -/*! - * Handy function for cleaning out meta result containers - * @param container - */ -template -void freeAndClearContainerResource(Container container) -{ - typename Container::iterator meta_it = container.begin(); - - for(; meta_it != container.end(); ++meta_it) - if(meta_it->second != NULL) - delete meta_it->second; - - container.clear(); -} - // temporary holds a map of pointers to class T, and destroys all pointers on delete. +class non_copiable +{ +public: + non_copiable() {} +private: + non_copiable& operator=(const non_copiable&) { return *this ;} + non_copiable(const non_copiable&) {} +}; + template -class t_RsGxsGenericDataTemporaryMap: public std::map +class t_RsGxsGenericDataTemporaryMap: public std::map, public non_copiable { public: virtual ~t_RsGxsGenericDataTemporaryMap() @@ -71,7 +64,7 @@ public: }; template -class t_RsGxsGenericDataTemporaryMapVector: public std::map > +class t_RsGxsGenericDataTemporaryMapVector: public std::map >, public non_copiable { public: virtual ~t_RsGxsGenericDataTemporaryMapVector() @@ -93,12 +86,33 @@ public: } }; +template +class t_RsGxsGenericDataTemporaryList: public std::list, public non_copiable +{ +public: + virtual ~t_RsGxsGenericDataTemporaryList() + { + clear() ; + } + + virtual void clear() + { + for(typename t_RsGxsGenericDataTemporaryList::iterator it = this->begin();it!=this->end();++it) + delete *it; + + std::list::clear() ; + } +}; + typedef t_RsGxsGenericDataTemporaryMap RsGxsGrpMetaTemporaryMap; typedef t_RsGxsGenericDataTemporaryMap RsNxsGrpDataTemporaryMap; typedef t_RsGxsGenericDataTemporaryMapVector RsGxsMsgMetaTemporaryMap ; typedef t_RsGxsGenericDataTemporaryMapVector RsNxsMsgDataTemporaryMap ; +typedef t_RsGxsGenericDataTemporaryList RsNxsGrpDataTemporaryList ; +typedef t_RsGxsGenericDataTemporaryList RsNxsMsgDataTemporaryList ; + #ifdef UNUSED template class RsGxsMetaDataTemporaryMapVector: public std::vector diff --git a/libretroshare/src/util/rssharedptr.h b/libretroshare/src/util/rssharedptr.h index 70213952e..ca54f85b2 100644 --- a/libretroshare/src/util/rssharedptr.h +++ b/libretroshare/src/util/rssharedptr.h @@ -12,6 +12,7 @@ /*! * Not thread safe!! + * And also has a memory leak. Do not use (csoler, 24 Jul 2017). */ template class RsSharedPtr diff --git a/tests/unittests/libretroshare/gxs/data_service/rsdataservice_test.cc b/tests/unittests/libretroshare/gxs/data_service/rsdataservice_test.cc index b12063a27..71d716ec2 100644 --- a/tests/unittests/libretroshare/gxs/data_service/rsdataservice_test.cc +++ b/tests/unittests/libretroshare/gxs/data_service/rsdataservice_test.cc @@ -36,49 +36,38 @@ void test_groupStoreAndRetrieve(){ setUp(); int nGrp = rand()%32; - std::map grps, grps_copy; + RsNxsGrpDataTemporaryList grps, grps_copy; RsNxsGrp* grp; RsGxsGrpMetaData* grpMeta; for(int i = 0; i < nGrp; i++) { std::pair p; - grp = new RsNxsGrp(RS_SERVICE_TYPE_PLUGIN_SIMPLE_FORUM); - grpMeta = new RsGxsGrpMetaData(); - p.first = grp; - p.second = grpMeta; - init_item(*grp); - 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; - } + grp = new RsNxsGrp(RS_SERVICE_TYPE_PLUGIN_SIMPLE_FORUM); + grpMeta = new RsGxsGrpMetaData(); + + init_item(*grp); + init_item(grpMeta); + + grpMeta->mGroupId = grp->grpId; + grp->metaData = grpMeta ; + + grps.push_back(grp); + } dStore->storeGroup(grps); - //use copy, a grps are deleted in store - grps.clear(); - grps = grps_copy; - RsNxsGrpDataTemporaryMap gR; RsGxsGrpMetaTemporaryMap grpMetaR; dStore->retrieveNxsGrps(gR, false, false); dStore->retrieveGxsGrpMetaData(grpMetaR); - std::map::iterator mit = grps.begin(); - bool grpMatch = true, grpMetaMatch = true; - for(; mit != grps.end(); mit++) + for( std::list::iterator mit = grps.begin(); mit != grps.end(); mit++) { - const RsGxsGroupId grpId = mit->first->grpId; + const RsGxsGroupId grpId = (*mit)->metaData->mGroupId; // check if it exists if(gR.find(grpId) == gR.end()) { @@ -86,8 +75,8 @@ void test_groupStoreAndRetrieve(){ break; } - RsNxsGrp *l = mit->first, - *r = gR[grpId]; + RsNxsGrp *l = (*mit); + RsNxsGrp *r = gR[grpId]; // assign transaction number // to right to as tn is not stored @@ -108,7 +97,7 @@ void test_groupStoreAndRetrieve(){ break; } - RsGxsGrpMetaData *l_Meta = mit->second, + RsGxsGrpMetaData *l_Meta = (*mit)->metaData, *r_Meta = grpMetaR[grpId]; // assign signSet and mGrpSize @@ -148,15 +137,18 @@ void test_messageStoresAndRetrieve() grpV.push_back(grpId0); grpV.push_back(grpId1); - std::map msgs; - std::map msgs_copy; + RsNxsMsgDataTemporaryList msgs; RsNxsMsg* msg = NULL; RsGxsMsgMetaData* msgMeta = NULL; int nMsgs = rand()%120; GxsMsgReq req; - t_RsGxsGenericDataTemporaryMap VergrpId0, VergrpId1; - t_RsGxsGenericDataTemporaryMap VerMetagrpId0, VerMetagrpId1; + // These ones are not in auto-delete structures because the data is deleted as part of the RsNxsMsg struct in the msgs list. + std::map VergrpId0 ; + std::map VergrpId1 ; + + std::map VerMetagrpId0; + std::map VerMetagrpId1; for(int i=0; imetaData = msgMeta ; + std::pair p(msg, msgMeta); int chosen = 0; if(rand()%50 > 24){ @@ -179,15 +174,9 @@ 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 vP(msg->msgId, msg_copy); - std::pair vPmeta(msg->msgId, msgMeta_copy); + std::pair vP(msg->msgId, msg); + std::pair vPmeta(msg->msgId, msgMeta); if(!chosen) { @@ -201,19 +190,12 @@ void test_messageStoresAndRetrieve() } - - msg = NULL; - msgMeta = NULL; - - msgs.insert(p); - msgs_copy.insert(std::make_pair(msg_copy, msgMeta_copy)); + msgs.push_back(msg); } req[grpV[0]] = std::vector(); // assign empty list for other dStore->storeMessage(msgs); - msgs.clear(); - msgs = msgs_copy; // now retrieve msgs for comparison // first selective retrieval diff --git a/tests/unittests/libretroshare/gxs/gen_exchange/genexchangetestservice.cc b/tests/unittests/libretroshare/gxs/gen_exchange/genexchangetestservice.cc index d6c8134a9..add532fdd 100644 --- a/tests/unittests/libretroshare/gxs/gen_exchange/genexchangetestservice.cc +++ b/tests/unittests/libretroshare/gxs/gen_exchange/genexchangetestservice.cc @@ -1,12 +1,15 @@ #include "genexchangetestservice.h" -GenExchangeTestService::GenExchangeTestService(RsGeneralDataService *dataServ, RsNetworkExchangeService * netService, - RsGixs* gixs) - : RsGenExchange(dataServ, netService, new RsDummySerialiser(), RS_SERVICE_TYPE_DUMMY, gixs, 0) +GenExchangeTestService::GenExchangeTestService(RsGeneralDataService *dataServ, RsNetworkExchangeService * netService, RsGixs* gixs) + : RsGenExchange(dataServ, netService, mSerializer = new RsDummySerialiser(), RS_SERVICE_TYPE_DUMMY, gixs, 0) { } +GenExchangeTestService::~GenExchangeTestService() +{ + delete mSerializer ; +} RsServiceInfo GenExchangeTestService::getServiceInfo() { RsServiceInfo info; diff --git a/tests/unittests/libretroshare/gxs/gen_exchange/genexchangetestservice.h b/tests/unittests/libretroshare/gxs/gen_exchange/genexchangetestservice.h index e22386582..011ee6973 100644 --- a/tests/unittests/libretroshare/gxs/gen_exchange/genexchangetestservice.h +++ b/tests/unittests/libretroshare/gxs/gen_exchange/genexchangetestservice.h @@ -11,6 +11,7 @@ class GenExchangeTestService : public RsGenExchange { public: GenExchangeTestService(RsGeneralDataService* dataServ, RsNetworkExchangeService* nxs, RsGixs* gixs); + virtual ~GenExchangeTestService(); void notifyChanges(std::vector& changes); @@ -104,6 +105,7 @@ public: void service_tick(); + RsSerialType *mSerializer ; }; #endif // GENEXCHANGETESTSERVICE_H diff --git a/tests/unittests/libretroshare/gxs/gen_exchange/rsgenexchange_test.cc b/tests/unittests/libretroshare/gxs/gen_exchange/rsgenexchange_test.cc index 3a402add5..32ffafe10 100644 --- a/tests/unittests/libretroshare/gxs/gen_exchange/rsgenexchange_test.cc +++ b/tests/unittests/libretroshare/gxs/gen_exchange/rsgenexchange_test.cc @@ -39,6 +39,8 @@ TEST(libretroshare_gxs, DISABLED_RsGenExchange) //GxsPublishMsgTest testMsgPublishing(&testService, dataStore); //testMsgPublishing.runTests(); + + //delete dataStore ; // deleted as a member of RsGenExchange } TEST(libretroshare_gxs, GetStats) @@ -54,4 +56,6 @@ TEST(libretroshare_gxs, GetStats) //GxsPublishMsgTest testMsgPublishing(&testService, dataStore); //testMsgPublishing.runTests(); + + //delete dataStore ; // deleted as a member of RsGenExchange } diff --git a/tests/unittests/libretroshare/gxs/nxs_test/nxsgrpsync_test.cc b/tests/unittests/libretroshare/gxs/nxs_test/nxsgrpsync_test.cc index 769eb4495..b926fe0e4 100644 --- a/tests/unittests/libretroshare/gxs/nxs_test/nxsgrpsync_test.cc +++ b/tests/unittests/libretroshare/gxs/nxs_test/nxsgrpsync_test.cc @@ -82,8 +82,8 @@ NxsGrpSync::NxsGrpSync(RsGcxs* circle, RsGixsReputation* reputation): RsGxsGroupId grpId = grp->grpId; - RsGeneralDataService::GrpStoreMap gsp; - gsp.insert(std::make_pair(grp, meta)); + RsNxsGrpDataTemporaryList gsp; + gsp.push_back(grp); mit->second->storeGroup(gsp); // the expected result is that each peer has the group of the others diff --git a/tests/unittests/libretroshare/gxs/nxs_test/nxsmsgsync_test.cc b/tests/unittests/libretroshare/gxs/nxs_test/nxsmsgsync_test.cc index f0b0e4dec..88cb4cf34 100644 --- a/tests/unittests/libretroshare/gxs/nxs_test/nxsmsgsync_test.cc +++ b/tests/unittests/libretroshare/gxs/nxs_test/nxsmsgsync_test.cc @@ -17,6 +17,20 @@ using namespace rs_nxs_test; +rs_nxs_test::NxsMsgSync::~NxsMsgSync() +{ + for(std::map::const_iterator it(mNxsNetMgrs.begin());it!=mNxsNetMgrs.end();++it) + delete it->second ; + + for(DataMap::const_iterator it(mDataServices.begin());it!=mDataServices.end();++it) + delete it->second ; + + delete mRep ; + delete mCircles; + delete mPgpUtils; +} + + rs_nxs_test::NxsMsgSync::NxsMsgSync() : mPgpUtils(NULL), mServType(0) { int numPeers = 2; @@ -79,8 +93,8 @@ rs_nxs_test::NxsMsgSync::NxsMsgSync() // first store grp RsGeneralDataService* ds = mit->second; RsNxsGrp* grp_clone = grp->clone(); - RsGeneralDataService::GrpStoreMap gsp; - gsp.insert(std::make_pair(grp_clone, grp_clone->metaData)); + RsNxsGrpDataTemporaryList gsp; + gsp.push_back(grp_clone); ds->storeGroup(gsp); RsGxsGroupId grpId = grp->grpId; @@ -95,10 +109,12 @@ rs_nxs_test::NxsMsgSync::NxsMsgSync() msg->grpId = grp->grpId; RsGxsMsgMetaData* msgMeta = new RsGxsMsgMetaData(); init_item(msgMeta); + msg->metaData = msgMeta; msgMeta->mGroupId = grp->grpId; msgMeta->mMsgId = msg->msgId; - RsGeneralDataService::MsgStoreMap msm; - msm.insert(std::make_pair(msg , msgMeta)); + + RsNxsMsgDataTemporaryList msm; + msm.push_back(msg); RsGxsMessageId msgId = msg->msgId; ds->storeMessage(msm); diff --git a/tests/unittests/libretroshare/gxs/nxs_test/nxsmsgsync_test.h b/tests/unittests/libretroshare/gxs/nxs_test/nxsmsgsync_test.h index f81af79e9..ee1c03711 100644 --- a/tests/unittests/libretroshare/gxs/nxs_test/nxsmsgsync_test.h +++ b/tests/unittests/libretroshare/gxs/nxs_test/nxsmsgsync_test.h @@ -17,6 +17,7 @@ namespace rs_nxs_test { public: NxsMsgSync(); + virtual ~NxsMsgSync(); void getPeers(std::list& peerIds); RsGeneralDataService* getDataService(const RsPeerId& peerId); RsNxsNetMgr* getDummyNetManager(const RsPeerId& peerId); diff --git a/tests/unittests/libretroshare/gxs/nxs_test/nxstesthub.cc b/tests/unittests/libretroshare/gxs/nxs_test/nxstesthub.cc index 36b288341..46dabe0a2 100644 --- a/tests/unittests/libretroshare/gxs/nxs_test/nxstesthub.cc +++ b/tests/unittests/libretroshare/gxs/nxs_test/nxstesthub.cc @@ -60,7 +60,7 @@ private: }; -rs_nxs_test::NxsTestHub::NxsTestHub(NxsTestScenario::pointer testScenario) +rs_nxs_test::NxsTestHub::NxsTestHub(NxsTestScenario *testScenario) : mTestScenario(testScenario), mMtx("NxsTestHub Mutex") { std::list peers; @@ -73,31 +73,43 @@ rs_nxs_test::NxsTestHub::NxsTestHub(NxsTestScenario::pointer testScenario) for(; cit != peers.end(); cit++) { - RsGxsNetService::pointer ns = RsGxsNetService::pointer( - new RsGxsNetService( - mTestScenario->getServiceType(), - mTestScenario->getDataService(*cit), - mTestScenario->getDummyNetManager(*cit), - new NotifyWithPeerId(*cit, *this), - mTestScenario->getServiceInfo(), - mTestScenario->getDummyReputations(*cit), - mTestScenario->getDummyCircles(*cit), - NULL, - mTestScenario->getDummyPgpUtils(), - true - ) - ); + NotifyWithPeerId *noti = new NotifyWithPeerId(*cit, *this) ; - NxsTestHubConnection *connection = - new NxsTestHubConnection(*cit, this); + mNotifys.push_back(noti) ; + + RsGxsNetService *ns = new RsGxsNetService( + mTestScenario->getServiceType(), + mTestScenario->getDataService(*cit), + mTestScenario->getDummyNetManager(*cit), + noti, + mTestScenario->getServiceInfo(), + mTestScenario->getDummyReputations(*cit), + mTestScenario->getDummyCircles(*cit), + NULL, + mTestScenario->getDummyPgpUtils(), + true + ); + + NxsTestHubConnection *connection = new NxsTestHubConnection(*cit, this); ns->setServiceServer(connection); + mConnections.push_back(connection) ; + mPeerNxsMap.insert(std::make_pair(*cit, ns)); } } -rs_nxs_test::NxsTestHub::~NxsTestHub() { +rs_nxs_test::NxsTestHub::~NxsTestHub() +{ + for(PeerNxsMap::const_iterator it(mPeerNxsMap.begin());it!=mPeerNxsMap.end();++it) + delete it->second ; + + for(std::list::const_iterator it(mNotifys.begin());it!=mNotifys.end();++it) + delete *it ; + + for(std::list::const_iterator it(mConnections.begin());it!=mConnections.end();++it) + delete *it ; } @@ -137,7 +149,7 @@ void rs_nxs_test::NxsTestHub::notifyNewMessages(const RsPeerId& pid, { RS_STACK_MUTEX(mMtx); /***** MTX LOCKED *****/ - std::map toStore; + RsNxsMsgDataTemporaryList toStore; std::vector::iterator it = messages.begin(); for(; it != messages.end(); it++) { @@ -145,13 +157,17 @@ void rs_nxs_test::NxsTestHub::notifyNewMessages(const RsPeerId& pid, RsGxsMsgMetaData* meta = new RsGxsMsgMetaData(); // local meta is not touched by the deserialisation routine // have to initialise it + + msg->metaData = meta ; + meta->mMsgStatus = 0; meta->mMsgSize = 0; meta->mChildTs = 0; meta->recvTS = 0; meta->validated = false; meta->deserialise(msg->meta.bin_data, &(msg->meta.bin_len)); - toStore.insert(std::make_pair(msg, meta)); + + toStore.push_back(msg); } RsGeneralDataService* ds = mTestScenario->getDataService(pid); @@ -163,14 +179,15 @@ void rs_nxs_test::NxsTestHub::notifyNewGroups(const RsPeerId& pid, std::vector toStore; + RsNxsGrpDataTemporaryList toStore; std::vector::iterator it = groups.begin(); for(; it != groups.end(); it++) { RsNxsGrp* grp = *it; RsGxsGrpMetaData* meta = new RsGxsGrpMetaData(); + grp->metaData = meta ; meta->deserialise(grp->meta.bin_data, grp->meta.bin_len); - toStore.insert(std::make_pair(grp, meta)); + toStore.push_back(grp); } RsGeneralDataService* ds = mTestScenario->getDataService(pid); @@ -227,7 +244,7 @@ void rs_nxs_test::NxsTestHub::data_tick() // then tick net services for(; it != mPeerNxsMap.end(); it++) { - RsGxsNetService::pointer s = it->second; + RsGxsNetService *s = it->second; s->tick(); } diff --git a/tests/unittests/libretroshare/gxs/nxs_test/nxstesthub.h b/tests/unittests/libretroshare/gxs/nxs_test/nxstesthub.h index a37ff78e3..ee9524e7e 100644 --- a/tests/unittests/libretroshare/gxs/nxs_test/nxstesthub.h +++ b/tests/unittests/libretroshare/gxs/nxs_test/nxstesthub.h @@ -11,7 +11,8 @@ // hence one could envision synchronising between an arbitrary number // of peers - +class NotifyWithPeerId; +class NxsTestHubConnection ; namespace rs_nxs_test { @@ -44,7 +45,7 @@ namespace rs_nxs_test * This constructs the test hub * for a give scenario in mind */ - NxsTestHub(NxsTestScenario::pointer testScenario); + NxsTestHub(NxsTestScenario* testScenario); /*! * This cleans up what ever testing resources are left @@ -101,13 +102,14 @@ namespace rs_nxs_test typedef std::pair PayLoad; - typedef std::map PeerNxsMap ; + typedef std::map PeerNxsMap ; - NxsTestScenario::pointer mTestScenario; + NxsTestScenario *mTestScenario; RsMutex mMtx; PeerNxsMap mPeerNxsMap; std::queue mPayLoad; - + std::list mNotifys; + std::list mConnections; }; } #endif // NXSTESTHUB_H diff --git a/tests/unittests/libretroshare/gxs/nxs_test/rsgxsnetservice_test.cc b/tests/unittests/libretroshare/gxs/nxs_test/rsgxsnetservice_test.cc index 47bfe8585..257b2de77 100644 --- a/tests/unittests/libretroshare/gxs/nxs_test/rsgxsnetservice_test.cc +++ b/tests/unittests/libretroshare/gxs/nxs_test/rsgxsnetservice_test.cc @@ -15,8 +15,7 @@ // disabled, because it fails after rebase to current master (did not fail in 2015, fails in 2016) TEST(libretroshare_gxs, DISABLED_gxs_grp_sync) { - rs_nxs_test::NxsTestScenario::pointer gsync_test = rs_nxs_test::NxsTestScenario::pointer( - new rs_nxs_test::NxsGrpSync()); + rs_nxs_test::NxsTestScenario *gsync_test = new rs_nxs_test::NxsGrpSync(); rs_nxs_test::NxsTestHub tHub(gsync_test); tHub.StartTest(); @@ -28,13 +27,13 @@ TEST(libretroshare_gxs, DISABLED_gxs_grp_sync) ASSERT_TRUE(tHub.testsPassed()); tHub.CleanUpTest(); + delete gsync_test ; } // disabled, not implemented (does currently the same as NxsGrpSync) TEST(libretroshare_gxs, DISABLED_gxs_grp_sync_delayed) { - rs_nxs_test::NxsTestScenario::pointer gsync_test = rs_nxs_test::NxsTestScenario::pointer( - new rs_nxs_test::NxsGrpSyncDelayed()); + rs_nxs_test::NxsTestScenario *gsync_test = new rs_nxs_test::NxsGrpSyncDelayed(); rs_nxs_test::NxsTestHub tHub(gsync_test); tHub.StartTest(); @@ -47,12 +46,12 @@ TEST(libretroshare_gxs, DISABLED_gxs_grp_sync_delayed) tHub.CleanUpTest(); + delete gsync_test ; } TEST(libretroshare_gxs, gxs_msg_sync) { - rs_nxs_test::NxsTestScenario::pointer gsync_test = rs_nxs_test::NxsTestScenario::pointer( - new rs_nxs_test::NxsMsgSync); + rs_nxs_test::NxsTestScenario *gsync_test = new rs_nxs_test::NxsMsgSync(); rs_nxs_test::NxsTestHub tHub(gsync_test); tHub.StartTest(); @@ -64,6 +63,7 @@ TEST(libretroshare_gxs, gxs_msg_sync) ASSERT_TRUE(tHub.testsPassed()); tHub.CleanUpTest(); + delete gsync_test ; } TEST(libretroshare_gxs, gxs_msg_sync_delayed) diff --git a/tests/unittests/libretroshare/serialiser/rsmsgitem_test.cc b/tests/unittests/libretroshare/serialiser/rsmsgitem_test.cc index a2b1369ad..838d367ad 100644 --- a/tests/unittests/libretroshare/serialiser/rsmsgitem_test.cc +++ b/tests/unittests/libretroshare/serialiser/rsmsgitem_test.cc @@ -104,7 +104,7 @@ void init_item(RsChatAvatarItem& cai) { std::string image_data; randString(LARGE_STR, image_data); - cai.image_data = new unsigned char[image_data.size()]; + cai.image_data = (unsigned char*)malloc(image_data.size()); memcpy(cai.image_data, image_data.c_str(), image_data.size()); cai.image_size = image_data.size();