Compare commits

...

1 Commits

Author SHA1 Message Date
Zack Radisic
3a37915cc6 fix leaking shell args 2024-07-09 18:42:08 +08:00
4 changed files with 10 additions and 7 deletions

View File

@@ -1065,9 +1065,9 @@ pub fn generateHeapSnapshot(globalObject: *JSC.JSGlobalObject, _: *JSC.CallFrame
}
pub fn runGC(globalObject: *JSC.JSGlobalObject, callframe: *JSC.CallFrame) JSC.JSValue {
const arguments_ = callframe.arguments(1);
const arguments_ = callframe.arguments(2);
const arguments = arguments_.slice();
return globalObject.bunVM().garbageCollect(arguments.len > 0 and arguments[0].isBoolean() and arguments[0].toBoolean());
return globalObject.bunVM().garbageCollect(arguments.len > 0 and arguments[0].isBoolean() and arguments[0].toBoolean(), arguments.len > 1 and arguments[1].isBoolean() and arguments[1].toBoolean());
}
pub fn shrink(globalObject: *JSC.JSGlobalObject, _: *JSC.CallFrame) JSC.JSValue {
globalObject.vm().shrinkFootprint();

View File

@@ -1024,9 +1024,9 @@ pub const VirtualMachine = struct {
return this.bundler.getPackageManager();
}
pub fn garbageCollect(this: *const VirtualMachine, sync: bool) JSValue {
pub fn garbageCollect(this: *const VirtualMachine, sync: bool, mimalloc_force: bool) JSValue {
@setCold(true);
Global.mimalloc_cleanup(false);
Global.mimalloc_cleanup(mimalloc_force);
if (sync)
return this.global.vm().runGC(true);
@@ -1036,7 +1036,7 @@ pub const VirtualMachine = struct {
pub inline fn autoGarbageCollect(this: *const VirtualMachine) void {
if (this.aggressive_garbage_collection != .none) {
_ = this.garbageCollect(this.aggressive_garbage_collection == .aggressive);
_ = this.garbageCollect(this.aggressive_garbage_collection == .aggressive, false);
}
}

View File

@@ -112,15 +112,17 @@ export function createBunShellTemplateFunction(createShellInterpreter, createPar
super((res, rej) => {
resolve = (code, stdout, stderr) => {
const out = new ShellOutput(stdout, stderr, code);
let out = new ShellOutput(stdout, stderr, code);
if (this.#throws && code !== 0) {
potentialError!.initialize(out, code);
rej(potentialError);
out = undefined;
} else {
// Set to undefined to hint to the GC that this is unused so it can
// potentially GC it earlier
potentialError = undefined;
res(out);
out = undefined;
}
};
reject = (code, stdout, stderr) => {
@@ -164,7 +166,7 @@ export function createBunShellTemplateFunction(createShellInterpreter, createPar
let interp = createShellInterpreter(this.#resolve, this.#reject, this.#args);
this.#args = undefined;
interp.run();
interp = undefined;
// process.nextTick(() => interp.run());
}
}

View File

@@ -1709,6 +1709,7 @@ pub const Interpreter = struct {
this.root_shell._buffered_stdout.owned.deinitWithAllocator(bun.default_allocator);
}
this.this_jsvalue = .zero;
this.args.deinit();
this.allocator.destroy(this);
}