diff options
author | Nikos Mavrogiannopoulos <nmav@redhat.com> | 2015-11-09 15:43:20 +0100 |
---|---|---|
committer | Nikos Mavrogiannopoulos <nmav@redhat.com> | 2015-11-09 15:43:20 +0100 |
commit | fa9a5cb246d2878b311457b8d2804890a208ee6d (patch) | |
tree | 323a87fdf7b276d495317f7f210618ed75c0872e /lib/crypto-backend.c | |
parent | 6312c13fb36baade5dd9df4c2f47c8671c5804ce (diff) | |
download | gnutls-fa9a5cb246d2878b311457b8d2804890a208ee6d.tar.gz |
crypto-backend: ensure there are no leaks on deinitialization
Diffstat (limited to 'lib/crypto-backend.c')
-rw-r--r-- | lib/crypto-backend.c | 18 |
1 files changed, 13 insertions, 5 deletions
diff --git a/lib/crypto-backend.c b/lib/crypto-backend.c index 32f66d3e14..9130e894ed 100644 --- a/lib/crypto-backend.c +++ b/lib/crypto-backend.c @@ -52,9 +52,12 @@ _algo_register(algo_list * al, int algorithm, int priority, void *s, int free_s) { algo_list *cl; algo_list *last_cl = al; + int ret; - if (al == NULL) - return gnutls_assert_val(GNUTLS_E_INVALID_REQUEST); + if (al == NULL) { + ret = gnutls_assert_val(GNUTLS_E_INVALID_REQUEST); + goto cleanup; + } /* look if there is any cipher with lowest priority. In that case do not add. */ @@ -63,7 +66,8 @@ _algo_register(algo_list * al, int algorithm, int priority, void *s, int free_s) if (cl->algorithm == algorithm) { if (cl->priority < priority) { gnutls_assert(); - return GNUTLS_E_CRYPTO_ALREADY_REGISTERED; + ret = GNUTLS_E_CRYPTO_ALREADY_REGISTERED; + goto cleanup; } else { /* the current has higher priority -> overwrite */ cl->algorithm = algorithm; @@ -82,16 +86,20 @@ _algo_register(algo_list * al, int algorithm, int priority, void *s, int free_s) if (cl == NULL) { gnutls_assert(); - return GNUTLS_E_MEMORY_ERROR; + ret = GNUTLS_E_MEMORY_ERROR; + goto cleanup; } last_cl->algorithm = algorithm; last_cl->priority = priority; last_cl->alg_data = s; + last_cl->free_alg_data = free_s; last_cl->next = cl; return 0; - + cleanup: + if (free_s) gnutls_free(s); + return ret; } static const void *_get_algo(algo_list * al, int algo) |