diff options
author | 2023-05-08 02:43:17 -0700 | |
---|---|---|
committer | 2023-05-08 02:43:17 -0700 | |
commit | 14597dbcdc318439d1ba3a7bdbf20d7b5d3c51ef (patch) | |
tree | 2bf89acad125071a9fcac8343a5644389f2ab4e3 | |
parent | f9d6a61676b8078ae5e88531f31ec5233dc1ceed (diff) | |
download | bun-14597dbcdc318439d1ba3a7bdbf20d7b5d3c51ef.tar.gz bun-14597dbcdc318439d1ba3a7bdbf20d7b5d3c51ef.tar.zst bun-14597dbcdc318439d1ba3a7bdbf20d7b5d3c51ef.zip |
Don't leak file handles
-rw-r--r-- | src/bundler/bundle_v2.zig | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/src/bundler/bundle_v2.zig b/src/bundler/bundle_v2.zig index 9cd7e3187..1ef06c94c 100644 --- a/src/bundler/bundle_v2.zig +++ b/src/bundler/bundle_v2.zig @@ -2014,7 +2014,7 @@ pub const BundleV2 = struct { } if (this.bun_watcher != null) { - if (empty_result.watcher_data.fd > 0) { + if (empty_result.watcher_data.fd > 0 and empty_result.watcher_data.fd != bun.invalid_fd) { this.bun_watcher.?.addFile( empty_result.watcher_data.fd, input_files.items(.source)[empty_result.source_index.get()].path.text, @@ -2033,7 +2033,7 @@ pub const BundleV2 = struct { { // to minimize contention, we add watcher here if (this.bun_watcher != null) { - if (result.watcher_data.fd > 0) { + if (result.watcher_data.fd > 0 and result.watcher_data.fd != bun.invalid_fd) { this.bun_watcher.?.addFile( result.watcher_data.fd, result.source.path.text, @@ -2477,7 +2477,12 @@ pub const ParseTask = struct { errdefer if (task.contents_or_fd == .fd) entry.deinit(allocator); - if (entry.fd > 2) task.contents_or_fd = .{ + const will_close_file_descriptor = task.contents_or_fd == .fd and entry.fd > 2 and this.ctx.bun_watcher == null; + if (will_close_file_descriptor) { + _ = JSC.Node.Syscall.close(entry.fd); + } + + if (!will_close_file_descriptor and entry.fd > 2) task.contents_or_fd = .{ .fd = .{ .file = entry.fd, .dir = bun.invalid_fd, @@ -2566,7 +2571,7 @@ pub const ParseTask = struct { 0, .watcher_data = .{ - .fd = if (task.contents_or_fd == .fd) task.contents_or_fd.fd.file else 0, + .fd = if (task.contents_or_fd == .fd and !will_close_file_descriptor) task.contents_or_fd.fd.file else 0, .dir_fd = if (task.contents_or_fd == .fd) task.contents_or_fd.fd.dir else 0, }, }; |