Skip to content

Commit

Permalink
buffer: do not leak memory if buffer is too big
Browse files Browse the repository at this point in the history
A recent pull request changed this method to throw when the buffer was
too big, but this meant that the `free` finalizer would never get
called, leading to a memory leak.

A previous version of this diff included a test provoking this behavior
with `v8.serialize`, but it unfortunately kept triggering the OOM
killer, so it was removed.

Refs: nodejs#40243

PR-URL: nodejs#43938
Reviewed-By: Darshan Sen <raisinten@gmail.com>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
  • Loading branch information
kvakil authored and Fyko committed Sep 15, 2022
1 parent 408948d commit 020f246
Showing 1 changed file with 1 addition and 0 deletions.
1 change: 1 addition & 0 deletions src/node_buffer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -497,6 +497,7 @@ MaybeLocal<Object> New(Environment* env,
if (length > kMaxLength) {
Isolate* isolate(env->isolate());
isolate->ThrowException(ERR_BUFFER_TOO_LARGE(isolate));
free(data);
return Local<Object>();
}
}
Expand Down

0 comments on commit 020f246

Please sign in to comment.