From 8bc459ba998abb4d0819a2c7d522c314bf65a4a4 Mon Sep 17 00:00:00 2001 From: Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> Date: Tue, 8 Nov 2022 22:08:49 -0800 Subject: Guard against closing the same pid twice --- src/bun.js/api/bun/subprocess.zig | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'src') 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); + } } } -- cgit v1.2.3