From 0783ddf57efc8c90af8906555b3164c5fc7424b6 Mon Sep 17 00:00:00 2001 From: Keyhan Vakil Date: Sun, 24 Jul 2022 16:06:08 -0700 Subject: [PATCH] buffer: do not leak memory if buffer is too big MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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: https://github.com/nodejs/node/pull/40243 PR-URL: https://github.com/nodejs/node/pull/43938 Reviewed-By: Darshan Sen Reviewed-By: Tobias Nießen Reviewed-By: Ben Noordhuis --- src/node_buffer.cc | 1 + 1 file changed, 1 insertion(+) diff --git a/src/node_buffer.cc b/src/node_buffer.cc index 5b2186feb8c707..aec97f15e2c809 100644 --- a/src/node_buffer.cc +++ b/src/node_buffer.cc @@ -497,6 +497,7 @@ MaybeLocal New(Environment* env, if (length > kMaxLength) { Isolate* isolate(env->isolate()); isolate->ThrowException(ERR_BUFFER_TOO_LARGE(isolate)); + free(data); return Local(); } }