src: fix potential memory leak on early return
authormscdex <mscdex@mscdex.net>
Sun, 21 Apr 2013 03:21:13 +0000 (23:21 -0400)
committerFedor Indutny <fedor.indutny@gmail.com>
Sun, 21 Apr 2013 03:30:21 +0000 (23:30 -0400)
src/node_crypto.cc

index 10d5d2c..797a39b 100644 (file)
@@ -3009,9 +3009,6 @@ class Sign : public ObjectWrap {
     unsigned int md_len;
     Local<Value> outString;
 
-    md_len = 8192; // Maximum key size is 8192 bits
-    md_value = new unsigned char[md_len];
-
     ASSERT_IS_BUFFER(args[0]);
     ssize_t len = Buffer::Length(args[0]);
 
@@ -3019,6 +3016,9 @@ class Sign : public ObjectWrap {
     ssize_t written = DecodeWrite(buf, len, args[0], BUFFER);
     assert(written == len);
 
+    md_len = 8192; // Maximum key size is 8192 bits
+    md_value = new unsigned char[md_len];
+
     int r = sign->SignFinal(&md_value, &md_len, buf, len);
     if (r == 0) {
       md_value = NULL;