aboutsummaryrefslogtreecommitdiff
path: root/src/bun.js
diff options
context:
space:
mode:
authorGravatar Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> 2022-11-08 22:08:49 -0800
committerGravatar Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> 2022-11-08 22:08:49 -0800
commit8bc459ba998abb4d0819a2c7d522c314bf65a4a4 (patch)
tree429bd89eae3b495ad56f1d8fce5298f50319bc9c /src/bun.js
parent5c312ec0c92746642958d086c8bf0c0fc8fdf068 (diff)
downloadbun-8bc459ba998abb4d0819a2c7d522c314bf65a4a4.tar.gz
bun-8bc459ba998abb4d0819a2c7d522c314bf65a4a4.tar.zst
bun-8bc459ba998abb4d0819a2c7d522c314bf65a4a4.zip
Guard against closing the same pid twice
Diffstat (limited to 'src/bun.js')
-rw-r--r--src/bun.js/api/bun/subprocess.zig13
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);
+ }
}
}