Skip to content

Commit

Permalink
Guard against closing the same pid twice
Browse files Browse the repository at this point in the history
  • Loading branch information
Jarred-Sumner committed Nov 9, 2022
1 parent 5c312ec commit 8bc459b
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/bun.js/api/bun/subprocess.zig
Original file line number Diff line number Diff line change
Expand Up @@ -297,10 +297,17 @@ pub const Subprocess = struct {
}

pub fn closePorts(this: *Subprocess) void {
const pidfd = this.pidfd;

if (comptime Environment.isLinux) {
if (this.pidfd != std.math.maxInt(std.os.fd_t)) {
_ = std.os.close(this.pidfd);
this.pidfd = std.math.maxInt(std.os.fd_t);
this.pidfd = std.math.maxInt(std.os.fd_t);
}

defer {
if (comptime Environment.isLinux) {
if (pidfd != std.math.maxInt(std.os.fd_t)) {
_ = std.os.close(pidfd);
}
}
}

Expand Down

0 comments on commit 8bc459b

Please sign in to comment.