From 19674c4d862ba7d30869099601ce849df6341dc7 Mon Sep 17 00:00:00 2001 From: thunder2 Date: Fri, 18 Jun 2010 22:58:27 +0000 Subject: [PATCH] memory leaks from missing gpgme_data_release - AuthGPG::privateSignCertificate - AuthGPG::privateTrustCertificate git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@3160 b45a01b8-16f6-495d-af2f-9b41ad6348cc --- libretroshare/src/pqi/authgpg.cc | 50 ++++++++++++++++++-------------- 1 file changed, 28 insertions(+), 22 deletions(-) diff --git a/libretroshare/src/pqi/authgpg.cc b/libretroshare/src/pqi/authgpg.cc index fd7e78b6e..a9022a2cb 100644 --- a/libretroshare/src/pqi/authgpg.cc +++ b/libretroshare/src/pqi/authgpg.cc @@ -1439,14 +1439,17 @@ int AuthGPG::privateSignCertificate(std::string id) gpgme_signers_clear(CTX); if(GPG_ERR_NO_ERROR != (ERR = gpgme_signers_add(CTX, ownKey))) { + gpgme_data_release(out); return 0; } - if(GPG_ERR_NO_ERROR != (ERR = gpgme_op_edit(CTX, signKey, keySignCallback, ¶ms, out))) { - + if(GPG_ERR_NO_ERROR != (ERR = gpgme_op_edit(CTX, signKey, keySignCallback, ¶ms, out))) { + gpgme_data_release(out); return 0; } + gpgme_data_release(out); + return 1; } @@ -1466,32 +1469,35 @@ int AuthGPG::privateTrustCertificate(std::string id, int trustlvl) return 0; } - { - RsStackMutex stack(gpgMtx); + { + RsStackMutex stack(gpgMtx); - gpgcert trustCert = mKeyList.find(id)->second; - gpgme_key_t trustKey = trustCert.key; - std::string trustString; - std::ostringstream trustStrOut; - trustStrOut << trustlvl; - class TrustParams sparams(trustStrOut.str()); - class EditParams params(TRUST_START, &sparams); - gpgme_data_t out; - gpg_error_t ERR; + gpgcert trustCert = mKeyList.find(id)->second; + gpgme_key_t trustKey = trustCert.key; + std::string trustString; + std::ostringstream trustStrOut; + trustStrOut << trustlvl; + class TrustParams sparams(trustStrOut.str()); + class EditParams params(TRUST_START, &sparams); + gpgme_data_t out; + gpg_error_t ERR; + if(GPG_ERR_NO_ERROR != (ERR = gpgme_data_new(&out))) { + return 0; + } - if(GPG_ERR_NO_ERROR != (ERR = gpgme_data_new(&out))) { - return 0; - } + if(GPG_ERR_NO_ERROR != (ERR = gpgme_op_edit(CTX, trustKey, trustCallback, ¶ms, out))) { + gpgme_data_release(out); + return 0; + } - if(GPG_ERR_NO_ERROR != (ERR = gpgme_op_edit(CTX, trustKey, trustCallback, ¶ms, out))) - return 0; + gpgme_data_release(out); - //the key ref has changed, we got to get rid of the old reference. - trustCert.key = NULL; - } + //the key ref has changed, we got to get rid of the old reference. + trustCert.key = NULL; + } - storeAllKeys_locked(); + storeAllKeys_locked(); return 1; }