Skip to content

Commit

Permalink
watcher/async: use mach_port_destroy for mach ports
Browse files Browse the repository at this point in the history
  • Loading branch information
mitchellh committed Aug 1, 2024
1 parent 4f98f5c commit e6d46f6
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/watcher/async.zig
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,10 @@ fn AsyncMachPort(comptime xev: type) type {
info: *anyopaque,
count: posix.system.mach_msg_type_number_t,
) posix.system.kern_return_t;
extern "c" fn mach_port_destroy(
task: posix.system.ipc_space_t,
name: posix.system.mach_port_name_t,
) posix.system.kern_return_t;

/// The mach port
port: posix.system.mach_port_name_t,
Expand All @@ -165,7 +169,7 @@ fn AsyncMachPort(comptime xev: type) type {
.SUCCESS => {}, // Success
else => return error.MachPortAllocFailed,
}
errdefer _ = posix.system.mach_port_deallocate(mach_self, mach_port);
errdefer _ = posix.system.mach_port_destroy(mach_self, mach_port);

// Insert a send right into the port since we also use this to send
switch (posix.system.getKernError(posix.system.mach_port_insert_right(
Expand Down Expand Up @@ -200,7 +204,7 @@ fn AsyncMachPort(comptime xev: type) type {
/// Clean up the async. This will forcibly deinitialize any resources
/// and may result in erroneous wait callbacks to be fired.
pub fn deinit(self: *Self) void {
_ = posix.system.mach_port_deallocate(
_ = mach_port_destroy(
posix.system.mach_task_self(),
self.port,
);
Expand Down

0 comments on commit e6d46f6

Please sign in to comment.