-
Notifications
You must be signed in to change notification settings - Fork 2.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: memory leak when reading chunks from a stream #16075
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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,11 @@ pub const StreamResult = union(Tag) { | |
const value = result.toJS(globalThis); | ||
value.ensureStillAlive(); | ||
|
||
switch (result.*) { | ||
.temporary => |*temporary| temporary.deinitWithAllocator(bun.default_allocator), | ||
.temporary_and_done => |*temporary_and_done| temporary_and_done.deinitWithAllocator(bun.default_allocator), | ||
else => {}, | ||
} | ||
result.* = .{ .temporary = .{} }; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Will this cause JSValues for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does line 1046 move or borrow? Man I miss Rust's borrow checker... |
||
promise.resolve(globalThis, value); | ||
}, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
temporary should mean that the StreamResult don't own the data and should be cloned, the owner (how created the StreamResult) should free it.