crypto: fix memory leak in SetDHParam
authorKarl Skomski <karl@skomski.com>
Fri, 14 Aug 2015 12:23:00 +0000 (14:23 +0200)
committerBen Noordhuis <info@bnoordhuis.nl>
Mon, 17 Aug 2015 19:23:07 +0000 (21:23 +0200)
PR-URL: https://github.com/nodejs/node/pull/2375
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
src/node_crypto.cc

index aa0b60e..5b45ccd 100644 (file)
@@ -805,10 +805,12 @@ void SecureContext::SetDHParam(const FunctionCallbackInfo<Value>& args) {
     return;
 
   const int keylen = BN_num_bits(dh->p);
-  if (keylen < 1024)
+  if (keylen < 1024) {
+    DH_free(dh);
     return env->ThrowError("DH parameter is less than 1024 bits");
-  else if (keylen < 2048)
+  } else if (keylen < 2048) {
     fprintf(stderr, "WARNING: DH parameter is less than 2048 bits\n");
+  }
 
   SSL_CTX_set_options(sc->ctx_, SSL_OP_SINGLE_DH_USE);
   int r = SSL_CTX_set_tmp_dh(sc->ctx_, dh);