Skip to content

Commit 9f4e3bf

Browse files
committed
add a shared boolean to GetResult to avoid deinit
1 parent a5dfe8a commit 9f4e3bf

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

src/browser/ScriptManager.zig

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,12 +343,14 @@ pub fn waitForModule(self: *ScriptManager, url: [:0]const u8) !GetResult {
343343
defer self.sync_module_pool.destroy(sync);
344344
defer self.sync_modules.removeByPtr(entry.key_ptr);
345345
return .{
346+
.shared = false,
346347
.buffer = sync.buffer,
347348
.buffer_pool = &self.buffer_pool,
348349
};
349350
}
350351

351352
return .{
353+
.shared = true,
352354
.buffer = sync.buffer,
353355
.buffer_pool = &self.buffer_pool,
354356
};
@@ -1012,6 +1014,7 @@ pub const AsyncModule = struct {
10121014
var self: *AsyncModule = @ptrCast(@alignCast(ctx));
10131015
defer self.manager.async_module_pool.destroy(self);
10141016
self.cb(self.cb_data, .{
1017+
.shared = false,
10151018
.buffer = self.buffer,
10161019
.buffer_pool = &self.manager.buffer_pool,
10171020
});
@@ -1035,8 +1038,13 @@ pub const AsyncModule = struct {
10351038
pub const GetResult = struct {
10361039
buffer: std.ArrayListUnmanaged(u8),
10371040
buffer_pool: *BufferPool,
1041+
shared: bool,
10381042

10391043
pub fn deinit(self: *GetResult) void {
1044+
// if the result is shared, don't deinit.
1045+
if (self.shared) {
1046+
return;
1047+
}
10401048
self.buffer_pool.release(self.buffer);
10411049
}
10421050

0 commit comments

Comments
 (0)