]> git.ipfire.org Git - thirdparty/gnutls.git/commitdiff
gnutls_aead_cipher_init: corrected potential memory leak
authorNikos Mavrogiannopoulos <nmav@redhat.com>
Wed, 29 Nov 2017 16:16:41 +0000 (17:16 +0100)
committerNikos Mavrogiannopoulos <nmav@redhat.com>
Wed, 29 Nov 2017 16:17:53 +0000 (17:17 +0100)
Signed-off-by: Nikos Mavrogiannopoulos <nmav@redhat.com>
lib/crypto-api.c

index 1a0b13b90cb75534d239811ab29f90f1584245d0..788627a1188f9b4f24b9d270db98838b4df3e9f2 100644 (file)
@@ -641,12 +641,13 @@ typedef struct api_aead_cipher_hd_st {
  *
  * Since: 3.4.0
  **/
-int gnutls_aead_cipher_init(gnutls_aead_cipher_hd_t * handle,
+int gnutls_aead_cipher_init(gnutls_aead_cipher_hd_t *handle,
                            gnutls_cipher_algorithm_t cipher,
-                           const gnutls_datum_t * key)
+                           const gnutls_datum_t *key)
 {
        api_aead_cipher_hd_st *h;
-       const cipher_entry_st* e;
+       const cipher_entry_st *e;
+       int ret;
 
        e = cipher_to_entry(cipher);
        if (e == NULL || e->type != CIPHER_AEAD)
@@ -660,9 +661,14 @@ int gnutls_aead_cipher_init(gnutls_aead_cipher_hd_t * handle,
 
        h = *handle;
 
-       return
+       ret =
            _gnutls_cipher_init(&h->ctx_enc, e, key,
                                NULL, 1);
+       if (ret < 0) {
+               gnutls_free(*handle);
+               *handle = NULL;
+       }
+       return ret;
 }
 
 /**