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: #40243

PR-URL: #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 committed Jul 24, 2022
1 parent f9b7380 commit e8e92ec
Showing 1 changed file with 1 addition and 0 deletions.
1 change: 1 addition & 0 deletions src/node_buffer.cc
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 e8e92ec

Please sign in to comment.