Skip to content

Commit

Permalink
fix(subprocess) use deref and use new (#13429)
Browse files Browse the repository at this point in the history
  • Loading branch information
cirospaciari authored Aug 20, 2024
1 parent f16d802 commit 1d188db
Showing 1 changed file with 19 additions and 8 deletions.
27 changes: 19 additions & 8 deletions src/bun.js/api/bun/subprocess.zig
Original file line number Diff line number Diff line change
Expand Up @@ -2066,25 +2066,36 @@ pub const Subprocess = struct {
} else {},
};

const process_allocator = bun.default_allocator;
var subprocess = process_allocator.create(Subprocess) catch {
globalThis.throwOutOfMemory();
return .zero;
};
var subprocess = Subprocess.new(.{
.globalThis = globalThis,
.process = undefined,
.pid_rusage = null,
.stdin = undefined,
.stdout = undefined,
.stderr = undefined,
.stdio_pipes = .{},
.on_exit_callback = .{},
.on_disconnect_callback = .{},
.ipc_data = null,
.ipc_callback =.{},
.flags = .{
.is_sync = is_sync,
},
});

var spawned = switch (bun.spawn.spawnProcess(
&spawn_options,
@ptrCast(argv.items.ptr),
@ptrCast(env_array.items.ptr),
) catch |err| {
process_allocator.destroy(subprocess);
subprocess.deref();
spawn_options.deinit();
globalThis.throwError(err, ": failed to spawn process");

return .zero;
}) {
.err => |err| {
process_allocator.destroy(subprocess);
subprocess.deref();
spawn_options.deinit();
globalThis.throwValue(err.toJSC(globalThis));
return .zero;
Expand All @@ -2102,7 +2113,7 @@ pub const Subprocess = struct {
@sizeOf(*Subprocess),
spawned.extra_pipes.items[@intCast(ipc_channel)].cast(),
) orelse {
process_allocator.destroy(subprocess);
subprocess.deref();
spawn_options.deinit();
globalThis.throw("failed to create socket pair", .{});
return .zero;
Expand Down

0 comments on commit 1d188db

Please sign in to comment.