From 638773628cf8568025d51fd9582ed11a5866be28 Mon Sep 17 00:00:00 2001 From: Ben Noordhuis <info@bnoordhuis.nl> Date: Wed, 7 Sep 2011 17:29:34 +0200 Subject: [PATCH] tls: new[] instead of malloc() in Connection::GetSession() --- src/node_crypto.cc | 22 +++++++--------------- 1 file changed, 7 insertions(+), 15 deletions(-) diff --git a/src/node_crypto.cc b/src/node_crypto.cc index 04ebbc6c9fc..36417040be3 100644 --- a/src/node_crypto.cc +++ b/src/node_crypto.cc @@ -1191,24 +1191,16 @@ Handle<Value> Connection::GetSession(const Arguments& args) { int slen = i2d_SSL_SESSION(sess, NULL); assert(slen > 0); - Local<Value> s; - if (slen > 0) { - void* pp = malloc(slen); - if (pp) - { - unsigned char* p = (unsigned char*)pp; - i2d_SSL_SESSION(sess, &p); - s = Encode(pp, slen, BINARY); - free(pp); - } - else - return False(); + unsigned char* sbuf = new unsigned char[slen]; + unsigned char* p = sbuf; + i2d_SSL_SESSION(sess, &p); + Local<Value> s = Encode(sbuf, slen, BINARY); + delete[] sbuf; + return scope.Close(s); } - else - return False(); - return scope.Close(s); + return Null(); } Handle<Value> Connection::SetSession(const Arguments& args) {