fixed bug due to not using realloc correctly (thanks valgrind)

git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@6385 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
csoler 2013-05-30 19:43:05 +00:00
parent 0d3d8ed2bd
commit b4f26dcf8f
2 changed files with 7 additions and 10 deletions

View File

@ -820,11 +820,14 @@ bool PGPHandler::importGPGKeyPair(const std::string& filename,PGPIdType& importe
void PGPHandler::addNewKeyToOPSKeyring(ops_keyring_t *kr,const ops_keydata_t& key)
{
kr->keys = (ops_keydata_t*)realloc(kr->keys,(kr->nkeys+1)*sizeof(ops_keydata_t)) ;
if(kr->nkeys >= kr->nkeys_allocated)
{
kr->keys = (ops_keydata_t *)realloc(kr->keys,(kr->nkeys+1)*sizeof(ops_keydata_t)) ;
kr->nkeys_allocated = kr->nkeys+1;
}
memset(&kr->keys[kr->nkeys],0,sizeof(ops_keydata_t)) ;
ops_keydata_copy(&kr->keys[kr->nkeys],&key) ;
kr->nkeys++ ;
kr->nkeys_allocated = kr->nkeys ;
}
bool PGPHandler::LoadCertificateFromString(const std::string& pgp_cert,PGPIdType& id,std::string& error_string)

View File

@ -876,15 +876,9 @@ void ops_keyring_remove_key(ops_keyring_t *keyring,int index)
ops_keydata_copy(&keyring->keys[index],&keyring->keys[keyring->nkeys-1]) ;
keydata_internal_free(&keyring->keys[keyring->nkeys-1]) ;
if(NULL == realloc(keyring->keys,(keyring->nkeys-1)*sizeof(ops_keydata_t)) )
{
fprintf(stderr,"ops_keyring_remove_key: ERROR: cannot re-alloc keyring memory.") ;
return ;
}
keyring->nkeys-- ;
keyring->nkeys_allocated-- ;
// keyring->nkeys_allocated is left untouched intentionnaly.
}
/**