mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-01-13 00:19:30 -05:00
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:
parent
1888b21998
commit
33a37054e8
@ -185,12 +185,14 @@ bool PGPHandler::GeneratePGPCertificate(const std::string& name, const std::stri
|
|||||||
static const int KEY_NUMBITS = 2048 ;
|
static const int KEY_NUMBITS = 2048 ;
|
||||||
|
|
||||||
ops_user_id_t uid ;
|
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 ;
|
uid.user_id = (unsigned char *)s ;
|
||||||
unsigned long int e = 17 ; // some prime number
|
unsigned long int e = 17 ; // some prime number
|
||||||
|
|
||||||
ops_keydata_t *key = ops_rsa_create_selfsigned_keypair(KEY_NUMBITS,e,&uid) ;
|
ops_keydata_t *key = ops_rsa_create_selfsigned_keypair(KEY_NUMBITS,e,&uid) ;
|
||||||
|
|
||||||
|
free(s) ;
|
||||||
|
|
||||||
if(!key)
|
if(!key)
|
||||||
return false ;
|
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_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
|
// 3 - read the file into a keyring
|
||||||
|
|
||||||
ops_keyring_t *tmp_keyring = allocateOPSKeyring() ;
|
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))
|
if(!ops_keyring_read_from_mem(tmp_keyring,ops_true,mem))
|
||||||
{
|
{
|
||||||
ops_keyring_free(tmp_keyring) ;
|
ops_keyring_free(tmp_keyring) ;
|
||||||
|
free(tmp_keyring) ;
|
||||||
ops_memory_release(mem) ;
|
ops_memory_release(mem) ;
|
||||||
|
free(mem) ;
|
||||||
|
|
||||||
std::cerr << "Could not read key. Format error?" << std::endl;
|
std::cerr << "Could not read key. Format error?" << std::endl;
|
||||||
error_string = std::string("Could not read key. Format error?") ;
|
error_string = std::string("Could not read key. Format error?") ;
|
||||||
return false ;
|
return false ;
|
||||||
}
|
}
|
||||||
ops_memory_release(mem) ;
|
ops_memory_release(mem) ;
|
||||||
|
free(mem) ;
|
||||||
error_string.clear() ;
|
error_string.clear() ;
|
||||||
|
|
||||||
std::cerr << "Key read correctly: " << std::endl;
|
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;
|
std::cerr << "Added the key in the main public keyring." << std::endl;
|
||||||
|
|
||||||
ops_keyring_free(tmp_keyring) ;
|
ops_keyring_free(tmp_keyring) ;
|
||||||
|
free(tmp_keyring) ;
|
||||||
|
|
||||||
return true ;
|
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) ;
|
memcpy(sign,ops_memory_get_data(memres),tlen) ;
|
||||||
*signlen = tlen ;
|
*signlen = tlen ;
|
||||||
|
|
||||||
|
ops_memory_release(memres) ;
|
||||||
|
free(memres) ;
|
||||||
|
ops_secret_key_free(secret_key) ;
|
||||||
|
free(secret_key) ;
|
||||||
|
|
||||||
return true ;
|
return true ;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -398,6 +398,9 @@ static ops_boolean_t write_secret_key_body(const ops_secret_key_t *key,
|
|||||||
|
|
||||||
ops_writer_pop(info);
|
ops_writer_pop(info);
|
||||||
|
|
||||||
|
free(crypt.encrypt_key) ;
|
||||||
|
free(crypt.decrypt_key) ;
|
||||||
|
|
||||||
return ops_true;
|
return ops_true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -86,12 +86,19 @@ void ops_keydata_free(ops_keydata_t *keydata)
|
|||||||
keydata->packets=NULL;
|
keydata->packets=NULL;
|
||||||
keydata->npackets=0;
|
keydata->npackets=0;
|
||||||
|
|
||||||
|
/* for(n=0;n<keydata->nsigs;++n)
|
||||||
|
{
|
||||||
|
ops_user_id_free(keydata->sigs[n].userid) ;
|
||||||
|
ops_packet_free(keydata->sigs[n].packet) ;
|
||||||
|
}*/
|
||||||
|
free(keydata->sigs) ;
|
||||||
|
|
||||||
if(keydata->type == OPS_PTAG_CT_PUBLIC_KEY)
|
if(keydata->type == OPS_PTAG_CT_PUBLIC_KEY)
|
||||||
ops_public_key_free(&keydata->key.pkey);
|
ops_public_key_free(&keydata->key.pkey);
|
||||||
else
|
else
|
||||||
ops_secret_key_free(&keydata->key.skey);
|
ops_secret_key_free(&keydata->key.skey);
|
||||||
|
|
||||||
free(keydata);
|
/* free(keydata); */
|
||||||
}
|
}
|
||||||
|
|
||||||
// \todo check where userid pointers are copied
|
// \todo check where userid pointers are copied
|
||||||
@ -145,18 +152,21 @@ void ops_keydata_copy(ops_keydata_t *dst,const ops_keydata_t *src)
|
|||||||
|
|
||||||
dst->uids = (ops_user_id_t*)ops_mallocz(src->nuids * sizeof(ops_user_id_t)) ;
|
dst->uids = (ops_user_id_t*)ops_mallocz(src->nuids * sizeof(ops_user_id_t)) ;
|
||||||
dst->nuids = src->nuids ;
|
dst->nuids = src->nuids ;
|
||||||
|
dst->nuids_allocated = src->nuids ;
|
||||||
|
|
||||||
for(n=0 ; n < src->nuids ; ++n)
|
for(n=0 ; n < src->nuids ; ++n)
|
||||||
ops_copy_userid(&dst->uids[n],&src->uids[n]) ;
|
ops_copy_userid(&dst->uids[n],&src->uids[n]) ;
|
||||||
|
|
||||||
dst->packets = (ops_packet_t*)ops_mallocz(src->npackets * sizeof(ops_packet_t)) ;
|
dst->packets = (ops_packet_t*)ops_mallocz(src->npackets * sizeof(ops_packet_t)) ;
|
||||||
dst->npackets = src->npackets ;
|
dst->npackets = src->npackets ;
|
||||||
|
dst->npackets_allocated = src->npackets ;
|
||||||
|
|
||||||
for(n=0 ; n < src->npackets ; ++n)
|
for(n=0 ; n < src->npackets ; ++n)
|
||||||
ops_copy_packet(&(dst->packets[n]),&(src->packets[n]));
|
ops_copy_packet(&(dst->packets[n]),&(src->packets[n]));
|
||||||
|
|
||||||
dst->nsigs = src->nsigs ;
|
dst->nsigs = src->nsigs ;
|
||||||
dst->sigs = (sigpacket_t*)ops_mallocz(src->nsigs * sizeof(sigpacket_t)) ;
|
dst->sigs = (sigpacket_t*)ops_mallocz(src->nsigs * sizeof(sigpacket_t)) ;
|
||||||
|
dst->nsigs_allocated = src->nsigs ;
|
||||||
|
|
||||||
for(n=0 ; n < src->nsigs ; ++n)
|
for(n=0 ; n < src->nsigs ; ++n)
|
||||||
{
|
{
|
||||||
@ -351,6 +361,8 @@ ops_secret_key_t *ops_decrypt_secret_key_from_data(const ops_keydata_t *key,
|
|||||||
|
|
||||||
ops_parse(pinfo);
|
ops_parse(pinfo);
|
||||||
|
|
||||||
|
ops_parse_info_delete(pinfo);
|
||||||
|
|
||||||
return arg.skey;
|
return arg.skey;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -792,6 +804,10 @@ ops_boolean_t ops_keyring_read_from_mem(ops_keyring_t *keyring, const ops_boolea
|
|||||||
*/
|
*/
|
||||||
void ops_keyring_free(ops_keyring_t *keyring)
|
void ops_keyring_free(ops_keyring_t *keyring)
|
||||||
{
|
{
|
||||||
|
int n;
|
||||||
|
for(n=0;n<keyring->nkeys;++n)
|
||||||
|
ops_keydata_free(&keyring->keys[n]) ;
|
||||||
|
|
||||||
free(keyring->keys);
|
free(keyring->keys);
|
||||||
keyring->keys=NULL;
|
keyring->keys=NULL;
|
||||||
keyring->nkeys=0;
|
keyring->nkeys=0;
|
||||||
|
@ -742,6 +742,7 @@ ops_keydata_t* ops_rsa_create_selfsigned_keypair(const int numbits, const unsign
|
|||||||
|| ops_add_selfsigned_userid_to_keydata(keydata, userid) != ops_true)
|
|| ops_add_selfsigned_userid_to_keydata(keydata, userid) != ops_true)
|
||||||
{
|
{
|
||||||
ops_keydata_free(keydata);
|
ops_keydata_free(keydata);
|
||||||
|
free(keydata) ;
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1251,6 +1251,8 @@ static int parse_user_id(ops_region_t *region,ops_parse_info_t *pinfo)
|
|||||||
|
|
||||||
CBP(pinfo,OPS_PTAG_CT_USER_ID,&content);
|
CBP(pinfo,OPS_PTAG_CT_USER_ID,&content);
|
||||||
|
|
||||||
|
free(C.user_id.user_id) ;
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1904,6 +1906,8 @@ static int parse_v4_signature(ops_region_t *region,ops_parse_info_t *pinfo)
|
|||||||
|
|
||||||
CBP(pinfo,OPS_PTAG_CT_SIGNATURE_FOOTER,&content);
|
CBP(pinfo,OPS_PTAG_CT_SIGNATURE_FOOTER,&content);
|
||||||
|
|
||||||
|
free(C.signature.info.v4_hashed_data) ;
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -3030,6 +3034,8 @@ static int ops_parse_one_packet(ops_parse_info_t *pinfo,
|
|||||||
}
|
}
|
||||||
pinfo->rinfo.alength=0;
|
pinfo->rinfo.alength=0;
|
||||||
|
|
||||||
|
free(C.packet.raw) ;
|
||||||
|
|
||||||
if(r < 0)
|
if(r < 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
|
@ -1314,6 +1314,7 @@ ops_memory_t* ops_sign_buf(const void* input, const size_t input_len, const ops_
|
|||||||
|
|
||||||
// tidy up
|
// tidy up
|
||||||
ops_writer_close(cinfo);
|
ops_writer_close(cinfo);
|
||||||
|
free(cinfo) ;
|
||||||
ops_create_signature_delete(sig);
|
ops_create_signature_delete(sig);
|
||||||
|
|
||||||
return mem;
|
return mem;
|
||||||
|
Loading…
Reference in New Issue
Block a user