From a4fb311721935ac9c25a9b7ffc9586a0e5069641 Mon Sep 17 00:00:00 2001 From: Guus Sliepen Date: Sat, 15 Jan 2011 23:11:25 +0100 Subject: [PATCH] Free resources in rsa_t. --- src/connection.c | 3 +++ src/gcrypt/rsa.c | 6 ++++++ src/gcrypt/rsa.h | 1 + src/openssl/rsa.c | 4 ++++ src/openssl/rsa.h | 1 + 5 files changed, 15 insertions(+) diff --git a/src/connection.c b/src/connection.c index 2fa789b..bdbf1c3 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 a729591..e38b50b 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 143f015..a76bfde 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 d39a1cb..a85bc8a 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 62836a8..933cc11 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 -- 2.25.1