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 <[email protected]>
Reviewed-By: Tobias Nießen <[email protected]>
Reviewed-By: Ben Noordhuis <[email protected]>
  • Loading branch information
kvakil authored 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
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 e8e92ec

Please sign in to comment.