Browse Source

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.
v0.11.6-release
Ben Noordhuis 12 years ago
parent
commit
9475ee41ad
  1. 9
      src/node_crypto.cc

9
src/node_crypto.cc

@ -81,6 +81,7 @@ using v8::Object;
using v8::Persistent; using v8::Persistent;
using v8::String; using v8::String;
using v8::ThrowException; using v8::ThrowException;
using v8::V8;
using v8::Value; using v8::Value;
@ -3463,8 +3464,14 @@ void RandomBytes(const FunctionCallbackInfo<Value>& args) {
RandomBytesRequest* req = new RandomBytesRequest(); RandomBytesRequest* req = new RandomBytesRequest();
req->error_ = 0; req->error_ = 0;
req->data_ = new char[size];
req->size_ = size; req->size_ = size;
req->data_ = static_cast<char*>(malloc(size));
if (req->data_ == NULL) {
delete req;
V8::LowMemoryNotification();
return ThrowError("Out of memory");
}
if (args[1]->IsFunction()) { if (args[1]->IsFunction()) {
Local<Object> obj = Object::New(); Local<Object> obj = Object::New();

Loading…
Cancel
Save