fix(kqueue): fix a possible fd leak on add_watch races
This commit is contained in:
parent
8e307e5863
commit
338c8460ff
2 changed files with 18 additions and 0 deletions
|
|
@ -315,6 +315,12 @@ pub fn add_watch(self: *@This(), allocator: std.mem.Allocator, path: []const u8)
|
|||
const is_file = if (stat) |s| std.posix.S.ISREG(s.mode) else false;
|
||||
const owned_path = try allocator.dupe(u8, path);
|
||||
self.watches_mutex.lock();
|
||||
if (self.watches.contains(path)) {
|
||||
self.watches_mutex.unlock();
|
||||
std.posix.close(path_fd);
|
||||
allocator.free(owned_path);
|
||||
return;
|
||||
}
|
||||
self.watches.put(allocator, owned_path, .{ .fd = path_fd, .is_file = is_file }) catch |e| {
|
||||
self.watches_mutex.unlock();
|
||||
allocator.free(owned_path);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue