aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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);
+ }
}
}