diff options
author | 2022-11-08 22:08:49 -0800 | |
---|---|---|
committer | 2022-11-08 22:08:49 -0800 | |
commit | 8bc459ba998abb4d0819a2c7d522c314bf65a4a4 (patch) | |
tree | 429bd89eae3b495ad56f1d8fce5298f50319bc9c /src | |
parent | 5c312ec0c92746642958d086c8bf0c0fc8fdf068 (diff) | |
download | bun-8bc459ba998abb4d0819a2c7d522c314bf65a4a4.tar.gz bun-8bc459ba998abb4d0819a2c7d522c314bf65a4a4.tar.zst bun-8bc459ba998abb4d0819a2c7d522c314bf65a4a4.zip |
Guard against closing the same pid twice
Diffstat (limited to 'src')
-rw-r--r-- | src/bun.js/api/bun/subprocess.zig | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/src/bun.js/api/bun/subprocess.zig b/src/bun.js/api/bun/subprocess.zig index b3fafd450..c82b4744f 100644 --- a/src/bun.js/api/bun/subprocess.zig +++ b/src/bun.js/api/bun/subprocess.zig @@ -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); + } } } |