Skip to content

Commit

Permalink
stream: fix memory leaks in writable
Browse files Browse the repository at this point in the history
Setting writecb and afterWriteTickInfo to null did not clear the value
in the state object.

Amends 35ec931 (stream: writable state bitmap).

Fixes #52228.
  • Loading branch information
orgads committed May 29, 2024
1 parent 8c6d43c commit 24b2499
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions lib/internal/streams/writable.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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;

Expand Down

0 comments on commit 24b2499

Please sign in to comment.