From 7b9f16b065c1d60474b426401bffbad43f17b943 Mon Sep 17 00:00:00 2001 From: Orgad Shaneh Date: Wed, 29 May 2024 08:52:11 +0300 Subject: [PATCH] stream: fix memory leaks in writable Setting writecb and afterWriteTickInfo to null did not clear the value in the state object. Amends 35ec931 (stream: writable state bitmap). Fixes #52228. --- lib/internal/streams/writable.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/internal/streams/writable.js b/lib/internal/streams/writable.js index a039e60b16c2c2..38f1cbadd39d1d 100644 --- a/lib/internal/streams/writable.js +++ b/lib/internal/streams/writable.js @@ -252,8 +252,8 @@ ObjectDefineProperties(WritableState.prototype, { enumerable: false, get() { return (this[kState] & kWriteCb) !== 0 ? this[kWriteCbValue] : nop; }, set(value) { + this[kWriteCbValue] = value; if (value) { - this[kWriteCbValue] = value; this[kState] |= kWriteCb; } else { this[kState] &= ~kWriteCb; @@ -268,8 +268,8 @@ ObjectDefineProperties(WritableState.prototype, { enumerable: false, get() { return (this[kState] & kAfterWriteTickInfo) !== 0 ? this[kAfterWriteTickInfoValue] : null; }, set(value) { + this[kAfterWriteTickInfoValue] = value; if (value) { - this[kAfterWriteTickInfoValue] = value; this[kState] |= kAfterWriteTickInfo; } else { this[kState] &= ~kAfterWriteTickInfo; @@ -615,7 +615,8 @@ function onwrite(stream, er) { const sync = (state[kState] & kSync) !== 0; const cb = (state[kState] & kWriteCb) !== 0 ? state[kWriteCbValue] : nop; - state[kState] &= ~(kWriting | kExpectWriteCb | kWriteCb); + state.writecb = null; + state[kState] &= ~(kWriting | kExpectWriteCb); state.length -= state.writelen; state.writelen = 0;