fixed several memory leaks

git-svn-id: http://svn.code.sf.net/p/retroshare/code/branches/v0.5-OpenPGP@5071 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
csoler 2012-04-01 16:43:23 +00:00
parent 1888b21998
commit 33a37054e8
6 changed files with 44 additions and 2 deletions

View file

@ -185,12 +185,14 @@ bool PGPHandler::GeneratePGPCertificate(const std::string& name, const std::stri
static const int KEY_NUMBITS = 2048 ;
ops_user_id_t uid ;
const char *s = strdup((name + " " + email + " (Generated by RetroShare)").c_str()) ;
char *s = strdup((name + " " + email + " (Generated by RetroShare)").c_str()) ;
uid.user_id = (unsigned char *)s ;
unsigned long int e = 17 ; // some prime number
ops_keydata_t *key = ops_rsa_create_selfsigned_keypair(KEY_NUMBITS,e,&uid) ;
free(s) ;
if(!key)
return false ;
@ -206,6 +208,9 @@ bool PGPHandler::GeneratePGPCertificate(const std::string& name, const std::stri
ops_write_transferable_secret_key(key,(unsigned char *)passphrase.c_str(),passphrase.length(),ops_false,cinfo);
ops_keydata_free(key) ;
free(key) ;
// 3 - read the file into a keyring
ops_keyring_t *tmp_keyring = allocateOPSKeyring() ;
@ -299,13 +304,16 @@ bool PGPHandler::LoadCertificateFromString(const std::string& pgp_cert,PGPIdType
if(!ops_keyring_read_from_mem(tmp_keyring,ops_true,mem))
{
ops_keyring_free(tmp_keyring) ;
free(tmp_keyring) ;
ops_memory_release(mem) ;
free(mem) ;
std::cerr << "Could not read key. Format error?" << std::endl;
error_string = std::string("Could not read key. Format error?") ;
return false ;
}
ops_memory_release(mem) ;
free(mem) ;
error_string.clear() ;
std::cerr << "Key read correctly: " << std::endl;
@ -325,6 +333,8 @@ bool PGPHandler::LoadCertificateFromString(const std::string& pgp_cert,PGPIdType
std::cerr << "Added the key in the main public keyring." << std::endl;
ops_keyring_free(tmp_keyring) ;
free(tmp_keyring) ;
return true ;
}
@ -362,6 +372,11 @@ bool PGPHandler::SignDataBin(const PGPIdType& id,const void *data, const uint32_
memcpy(sign,ops_memory_get_data(memres),tlen) ;
*signlen = tlen ;
ops_memory_release(memres) ;
free(memres) ;
ops_secret_key_free(secret_key) ;
free(secret_key) ;
return true ;
}