Fix a memleak in ec_copy_parameters.
authorBernd Edlinger <bernd.edlinger@hotmail.de>
Tue, 13 Jun 2017 05:22:50 +0000 (07:22 +0200)
committerRich Salz <rsalz@openssl.org>
Tue, 13 Jun 2017 17:27:25 +0000 (13:27 -0400)
Reviewed-by: Matt Caswell <matt@openssl.org>
Reviewed-by: Rich Salz <rsalz@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/3666)

crypto/ec/ec_ameth.c

index fa5bd0318ca70b348e71171f402ffb8b63bd9137..b66adf2bbc246dc6f556e8ceeef45aa2a6ba0923 100644 (file)
@@ -298,17 +298,21 @@ static int ec_missing_parameters(const EVP_PKEY *pkey)
 static int ec_copy_parameters(EVP_PKEY *to, const EVP_PKEY *from)
 {
     EC_GROUP *group = EC_GROUP_dup(EC_KEY_get0_group(from->pkey.ec));
+
     if (group == NULL)
         return 0;
     if (to->pkey.ec == NULL) {
         to->pkey.ec = EC_KEY_new();
         if (to->pkey.ec == NULL)
-            return 0;
+            goto err;
     }
     if (EC_KEY_set_group(to->pkey.ec, group) == 0)
-        return 0;
+        goto err;
     EC_GROUP_free(group);
     return 1;
+ err:
+    EC_GROUP_free(group);
+    return 0;
 }
 
 static int ec_cmp_parameters(const EVP_PKEY *a, const EVP_PKEY *b)