Skip to content

Commit

Permalink
fix: memory leak when reading chunks from a stream
Browse files Browse the repository at this point in the history
  • Loading branch information
DonIsaac committed Dec 31, 2024
1 parent e96dded commit 3274514
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/bun.js/webcore/streams.zig
Original file line number Diff line number Diff line change
Expand Up @@ -709,6 +709,8 @@ pub const StreamResult = union(Tag) {
switch (this.*) {
.owned => |*owned| owned.deinitWithAllocator(bun.default_allocator),
.owned_and_done => |*owned_and_done| owned_and_done.deinitWithAllocator(bun.default_allocator),
.temporary => |*temporary| temporary.deinitWithAllocator(bun.default_allocator),
.temporary_and_done => |*temporary_and_done| temporary_and_done.deinitWithAllocator(bun.default_allocator),
.err => |err| {
if (err == .JSValue) {
err.JSValue.unprotect();
Expand Down Expand Up @@ -1021,6 +1023,12 @@ pub const StreamResult = union(Tag) {
const value = result.toJS(globalThis);
value.ensureStillAlive();

switch (result.*) {
.temporary, .temporary_and_done => {
result.deinit();
},
else => {},
}
result.* = .{ .temporary = .{} };
promise.resolve(globalThis, value);
},
Expand Down

0 comments on commit 3274514

Please sign in to comment.