From 7e226558e4a06851c66d2d409403b046b057b46f Mon Sep 17 00:00:00 2001 From: thunder2 Date: Fri, 13 Jul 2012 22:10:52 +0000 Subject: [PATCH] Fixed some memory leaks when config could not be loaded/saved. git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@5294 b45a01b8-16f6-495d-af2f-9b41ad6348cc --- libretroshare/src/pqi/p3cfgmgr.cc | 17 +++++++++++++++-- libretroshare/src/pqi/pqibin.cc | 7 ++++++- libretroshare/src/pqi/pqistore.cc | 6 ++++-- 3 files changed, 25 insertions(+), 5 deletions(-) diff --git a/libretroshare/src/pqi/p3cfgmgr.cc b/libretroshare/src/pqi/p3cfgmgr.cc index 29354c4ab..fac75c5e7 100644 --- a/libretroshare/src/pqi/p3cfgmgr.cc +++ b/libretroshare/src/pqi/p3cfgmgr.cc @@ -310,6 +310,11 @@ bool p3ConfigMgr::backedUpFileSave(const std::string& fname, const std::string& << fname_backup << " to " << fname << std::endl << sign_fname_backup << " to " << sign_fname << std::endl; #endif + if (config_buff) + delete[] config_buff; + if (sign_buff) + delete[] sign_buff; + return true; } @@ -323,6 +328,9 @@ bool p3ConfigMgr::backedUpFileSave(const std::string& fname, const std::string& #ifdef CONFIG_DEBUG std::cerr << "p3Config::backedUpFileSave() fopen failed for file: " << fname_backup << std::endl; #endif + delete[] config_buff; + delete[] sign_buff; + return true; } @@ -755,7 +763,10 @@ bool p3Config::loadAttempt(const std::string& cfgFname,const std::string& signFn BinMemInterface *signbio = new BinMemInterface(1000, BIN_FLAGS_READABLE); if(!signbio->readfromfile(signFname.c_str())) + { + delete signbio; return false; + } std::string signatureStored((char *) signbio->memptr(), signbio->memsize()); @@ -763,11 +774,11 @@ bool p3Config::loadAttempt(const std::string& cfgFname,const std::string& signFn std::string strHash(Hash()); AuthSSL::getAuthSSL()->SignData(strHash.c_str(), strHash.length(), signatureRead); + delete signbio; + if(signatureRead != signatureStored) return false; - delete signbio; - return true; } @@ -884,6 +895,7 @@ bool p3Config::getHashAttempt(const std::string& loadHash, std::string& hashstr, setHash(""); + delete stream; return false; } @@ -1125,6 +1137,7 @@ bool p3Config::backedUpFileSave(const std::string& cfg_fname, const std::string& { getPqiNotify()->AddSysMessage(0, RS_SYS_WARNING, "Write error", "Error while writing backup configuration file " + cfg_fname_backup + "\nIs your disc full or out of quota ?"); fclose(cfg_file); + delete[] buff; return false ; } diff --git a/libretroshare/src/pqi/pqibin.cc b/libretroshare/src/pqi/pqibin.cc index a7a88cce8..a3f450d93 100644 --- a/libretroshare/src/pqi/pqibin.cc +++ b/libretroshare/src/pqi/pqibin.cc @@ -237,13 +237,18 @@ int BinEncryptedFileInterface::readdata(void* data, int len) if(-1 == BinFileInterface::readdata(encryptedData, encrypDataLen)) + { + delete[] encryptedData; return -1; + } if((encrypDataLen > 0) && (encryptedData != NULL)) { - if(!AuthSSL::getAuthSSL()->decrypt((void*&)(this->data), sizeData, encryptedData, encrypDataLen)) + { + delete[] encryptedData; return -1; + } haveData = true; delete[] encryptedData; diff --git a/libretroshare/src/pqi/pqistore.cc b/libretroshare/src/pqi/pqistore.cc index 85b7d62fc..c3a0e663b 100644 --- a/libretroshare/src/pqi/pqistore.cc +++ b/libretroshare/src/pqi/pqistore.cc @@ -391,15 +391,17 @@ bool pqiSSLstore::encryptedSendItems(const std::list& rsItemList) delete *it; } + bool result = true; + if(sizeItems == offset) enc_bio->senddata(data, sizeItems); else - return false; + result = false; if(data != NULL) delete[] data; - return true; + return result; } bool pqiSSLstore::getEncryptedItems(std::list& rsItemList)