diff options
author | Ben Noordhuis <info@bnoordhuis.nl> | 2015-08-08 00:03:00 +0300 |
---|---|---|
committer | Ben Noordhuis <info@bnoordhuis.nl> | 2015-08-13 21:03:41 +0300 |
commit | 64577463dfbc7ebe646c6c5a06e4b309b2757205 (patch) | |
tree | 545d278d9489706ba1689d08cf01b0d712c79e77 /src/node_buffer.h | |
parent | 27813339cf713275fa7bbf2ae497d13b66aa78ce (diff) |
src: plug memory leaks
In a few places dynamic memory was passed to the Buffer::New() overload
that makes a copy of the input, not the one that takes ownership.
This commit is a band-aid to fix the memory leaks. Longer term, we
should look into using C++11 move semantics more effectively.
Fixes: https://github.com/nodejs/node/issues/2308
PR-URL: https://github.com/nodejs/node/pull/2352
Reviewed-By: Fedor Indutny <fedor@indutny.com>
Reviewed-By: Trevor Norris <trev.norris@gmail.com>
Diffstat (limited to 'src/node_buffer.h')
-rw-r--r-- | src/node_buffer.h | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/src/node_buffer.h b/src/node_buffer.h index 5b935b8c063..f7c88f60e03 100644 --- a/src/node_buffer.h +++ b/src/node_buffer.h @@ -67,12 +67,17 @@ static inline bool IsWithinBounds(size_t off, size_t len, size_t max) { // in src/node_internals.h because of a circular dependency. #if defined(NODE_WANT_INTERNALS) v8::MaybeLocal<v8::Object> New(Environment* env, size_t size); +// Makes a copy of |data|. v8::MaybeLocal<v8::Object> New(Environment* env, const char* data, size_t len); +// Takes ownership of |data|. v8::MaybeLocal<v8::Object> New(Environment* env, char* data, size_t length, FreeCallback callback, void* hint); +// Takes ownership of |data|. Must allocate |data| with malloc() or realloc() +// because ArrayBufferAllocator::Free() deallocates it again with free(). +// Mixing operator new and free() is undefined behavior so don't do that. v8::MaybeLocal<v8::Object> Use(Environment* env, char* data, size_t length); #endif // defined(NODE_WANT_INTERNALS) |