From c949bf124e1f6124cbb8501296abbd44d5ce85f8 Mon Sep 17 00:00:00 2001 From: Keyhan Vakil Date: Fri, 22 Jul 2022 02:11:45 +0000 Subject: [PATCH] buffer: do not leak memory if buffer is too big 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 --- 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(); } }