From 327451429da2ece4e8ce5bc1ee791bf6d8409939 Mon Sep 17 00:00:00 2001 From: Don Isaac Date: Mon, 30 Dec 2024 23:17:07 -0500 Subject: [PATCH] fix: memory leak when reading chunks from a stream --- src/bun.js/webcore/streams.zig | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/bun.js/webcore/streams.zig b/src/bun.js/webcore/streams.zig index 8c7f348dfbf4b0..70f47f1695c646 100644 --- a/src/bun.js/webcore/streams.zig +++ b/src/bun.js/webcore/streams.zig @@ -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(); @@ -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); },