From 9475ee41ad302d05c641b99cebef3e3f70b6c18f Mon Sep 17 00:00:00 2001 From: Ben Noordhuis Date: Fri, 16 Aug 2013 16:36:21 +0200 Subject: [PATCH] crypto: don't mix new[] and free() RandomBytes() allocated memory with new[] which was then handed off to Buffer::Use() which eventually releases it again with free(). Mixing the two is technically a violation of the spec and besides, it's generally frowned upon. --- src/node_crypto.cc | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/node_crypto.cc b/src/node_crypto.cc index 0239e7454c..665010bd1b 100644 --- a/src/node_crypto.cc +++ b/src/node_crypto.cc @@ -81,6 +81,7 @@ using v8::Object; using v8::Persistent; using v8::String; using v8::ThrowException; +using v8::V8; using v8::Value; @@ -3463,8 +3464,14 @@ void RandomBytes(const FunctionCallbackInfo& args) { RandomBytesRequest* req = new RandomBytesRequest(); req->error_ = 0; - req->data_ = new char[size]; req->size_ = size; + req->data_ = static_cast(malloc(size)); + + if (req->data_ == NULL) { + delete req; + V8::LowMemoryNotification(); + return ThrowError("Out of memory"); + } if (args[1]->IsFunction()) { Local obj = Object::New();