]> granicus.if.org Git - pdns/commitdiff
Release memory in case of error in the OpenSSL ECDSA constructor
authorRemi Gacogne <remi.gacogne@powerdns.com>
Mon, 3 Sep 2018 07:43:45 +0000 (09:43 +0200)
committerRemi Gacogne <remi.gacogne@powerdns.com>
Mon, 3 Sep 2018 07:43:45 +0000 (09:43 +0200)
The current code will only fail to release the allocated memory if
called with an invalid algorithm, which won't happen, or if a
memory allocation fails in which case this might not matter much.
Still, it's cleaner to release the memory properly and might avoid
mistakes later if we look at this code while implementing a new
crypto backend.

pdns/opensslsigners.cc

index daff5a538480a4d1012f1c8ed5924fd5c5fc54ec..6a2e8569403955d9847f39b2b608a99cabbb5953 100644 (file)
@@ -616,14 +616,19 @@ public:
       d_ecgroup = EC_GROUP_new_by_curve_name(NID_secp384r1);
       d_len = 48;
     } else {
+      EC_KEY_free(d_eckey);
       throw runtime_error(getName()+" unknown algorithm "+std::to_string(d_algorithm));
     }
+
     if (d_ecgroup == NULL) {
+      EC_KEY_free(d_eckey);
       throw runtime_error(getName()+" allocation of group structure failed");
     }
 
-    ret = EC_KEY_set_group(d_eckey,d_ecgroup);
+    ret = EC_KEY_set_group(d_eckey, d_ecgroup);
     if (ret != 1) {
+      EC_KEY_free(d_eckey);
+      EC_GROUP_free(d_ecgroup);
       throw runtime_error(getName()+" setting key group failed");
     }