From: Guus Sliepen Date: Sat, 15 Jan 2011 22:11:25 +0000 (+0100) Subject: Free resources in rsa_t. X-Git-Url: https://git.tinc-vpn.org/git/browse?a=commitdiff_plain;ds=sidebyside;h=a4fb311721935ac9c25a9b7ffc9586a0e5069641;p=tinc Free resources in rsa_t. --- diff --git a/src/connection.c b/src/connection.c index 2fa789bd..bdbf1c3d 100644 --- a/src/connection.c +++ b/src/connection.c @@ -78,6 +78,9 @@ void free_connection(connection_t *c) { if(c->thread) thread_destroy(&c->thread); + if(c->rsa) + rsa_free(c->rsa); + free(c); } diff --git a/src/gcrypt/rsa.c b/src/gcrypt/rsa.c index a729591d..e38b50b0 100644 --- a/src/gcrypt/rsa.c +++ b/src/gcrypt/rsa.c @@ -300,3 +300,9 @@ bool rsa_private_decrypt(rsa_t *rsa, void *in, size_t len, void *out) { return true; } + +void rsa_free(rsa_t *rsa) { + gcry_mpi_release(rsa->n); + gcry_mpi_release(rsa->e); + gcry_mpi_release(rsa->d); +} diff --git a/src/gcrypt/rsa.h b/src/gcrypt/rsa.h index 143f0153..a76bfde9 100644 --- a/src/gcrypt/rsa.h +++ b/src/gcrypt/rsa.h @@ -35,5 +35,6 @@ extern bool rsa_read_pem_private_key(rsa_t *rsa, FILE *fp); extern size_t rsa_size(rsa_t *rsa); extern bool rsa_public_encrypt(rsa_t *rsa, void *in, size_t len, void *out); extern bool rsa_private_decrypt(rsa_t *rsa, void *in, size_t len, void *out); +extern void rsa_free(rsa_t *rsa); #endif diff --git a/src/openssl/rsa.c b/src/openssl/rsa.c index d39a1cba..a85bc8a2 100644 --- a/src/openssl/rsa.c +++ b/src/openssl/rsa.c @@ -88,3 +88,7 @@ bool rsa_private_decrypt(rsa_t *rsa, void *in, size_t len, void *out) { logger(LOG_ERR, "Unable to perform RSA decryption: %s", ERR_error_string(ERR_get_error(), NULL)); return false; } + +void rsa_free(rsa_t *rsa) { + RSA_free(*rsa); +} diff --git a/src/openssl/rsa.h b/src/openssl/rsa.h index 62836a8e..933cc114 100644 --- a/src/openssl/rsa.h +++ b/src/openssl/rsa.h @@ -31,5 +31,6 @@ extern bool rsa_read_pem_private_key(rsa_t *rsa, FILE *fp); extern size_t rsa_size(rsa_t *rsa); extern bool rsa_public_encrypt(rsa_t *rsa, void *in, size_t inlen, void *out); extern bool rsa_private_decrypt(rsa_t *rsa, void *in, size_t inlen, void *out); +extern void rsa_free(rsa_t *rsa); #endif