]> git.ipfire.org Git - thirdparty/gnutls.git/commitdiff
Eliminated memory leak on failed curve assignment.
authorNikos Mavrogiannopoulos <nmav@redhat.com>
Wed, 14 May 2014 13:47:48 +0000 (15:47 +0200)
committerNikos Mavrogiannopoulos <nmav@redhat.com>
Wed, 14 May 2014 13:47:48 +0000 (15:47 +0200)
The memory leak was uncovered by the Codenomicon TLS suite.

lib/nettle/pk.c

index 303cbaa78eed743a5c59dcf3fc4ef06424e6ce1b..4422ff02ab479d381af1f1ec44ef2a3157c406cd 100644 (file)
@@ -130,8 +130,10 @@ _ecc_params_to_privkey(const gnutls_pk_params_st * pk_params,
                       const struct ecc_curve *curve)
 {
        ecc_scalar_init(priv, curve);
-       if (ecc_scalar_set(priv, pk_params->params[ECC_K]) == 0)
+       if (ecc_scalar_set(priv, pk_params->params[ECC_K]) == 0) {
+               ecc_scalar_clear(priv);
                return gnutls_assert_val(GNUTLS_E_INVALID_REQUEST);
+       }
 
        return 0;
 }
@@ -142,8 +144,10 @@ _ecc_params_to_pubkey(const gnutls_pk_params_st * pk_params,
 {
        ecc_point_init(pub, curve);
        if (ecc_point_set
-           (pub, pk_params->params[ECC_X], pk_params->params[ECC_Y]) == 0)
+           (pub, pk_params->params[ECC_X], pk_params->params[ECC_Y]) == 0) {
+               ecc_point_clear(pub);
                return gnutls_assert_val(GNUTLS_E_INVALID_REQUEST);
+       }
 
        return 0;
 }