From e64971c0b26f5e4bdf945cbc8ea9514814f2e873 Mon Sep 17 00:00:00 2001 From: Jarred Sumner Date: Tue, 30 Jul 2024 23:11:04 -0700 Subject: [PATCH] Free more data on worker destruction --- src/bun.js/api/Timer.zig | 10 ++++++++++ src/bun.js/javascript.zig | 1 + src/bun.js/rare_data.zig | 20 ++++++++++++++++++++ 3 files changed, 31 insertions(+) diff --git a/src/bun.js/api/Timer.zig b/src/bun.js/api/Timer.zig index 782bf3a231..67df086f46 100644 --- a/src/bun.js/api/Timer.zig +++ b/src/bun.js/api/Timer.zig @@ -331,6 +331,16 @@ pub const All = struct { return JSValue.jsUndefined(); } + pub fn deinit(this: *All) void { + if (Environment.isWindows) { + this.uv_timer.stop(); + } + + this.maps.setImmediate.clearAndFree(bun.default_allocator); + this.maps.setTimeout.clearAndFree(bun.default_allocator); + this.maps.setInterval.clearAndFree(bun.default_allocator); + } + const Shimmer = @import("../bindings/shimmer.zig").Shimmer; pub const shim = Shimmer("Bun", "Timer", @This()); diff --git a/src/bun.js/javascript.zig b/src/bun.js/javascript.zig index c783385a40..246f196eac 100644 --- a/src/bun.js/javascript.zig +++ b/src/bun.js/javascript.zig @@ -2433,6 +2433,7 @@ pub const VirtualMachine = struct { // TODO: pub fn deinit(this: *VirtualMachine) void { + this.timer.deinit(); this.source_mappings.deinit(); if (this.rare_data) |rare_data| { rare_data.deinit(); diff --git a/src/bun.js/rare_data.zig b/src/bun.js/rare_data.zig index b0c929ea36..f96dd75840 100644 --- a/src/bun.js/rare_data.zig +++ b/src/bun.js/rare_data.zig @@ -402,4 +402,24 @@ pub fn deinit(this: *RareData) void { if (this.boring_ssl_engine) |engine| { _ = bun.BoringSSL.ENGINE_free(engine); } + + if (this.stderr_store) |store| { + this.stderr_store = null; + store.deref(); + } + + if (this.stdout_store) |store| { + this.stdout_store = null; + store.deref(); + } + + if (this.stdin_store) |store| { + this.stdin_store = null; + store.deref(); + } + + if (this.entropy_cache) |cache| { + this.entropy_cache = null; + bun.default_allocator.destroy(cache); + } }