From: Remi Gacogne Date: Mon, 3 Sep 2018 07:43:45 +0000 (+0200) Subject: Release memory in case of error in the OpenSSL ECDSA constructor X-Git-Tag: auth-4.1.5~1^2~2^2 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=e66c48ca80792f766a9a191d50cb6858075fdaf1;p=pdns Release memory in case of error in the OpenSSL ECDSA constructor 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. (cherry picked from commit b141d89b27e52c3a8e76ca79ec5201d001f4fce9) --- diff --git a/pdns/opensslsigners.cc b/pdns/opensslsigners.cc index 8e3bb547b..abfe552bd 100644 --- a/pdns/opensslsigners.cc +++ b/pdns/opensslsigners.cc @@ -597,14 +597,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"); }