authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2025-10-27 16:59:31-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2025-10-29 06:20:51-07:00
logc8739d6953b62de30827a484f94cc8add8c22dd9
treebe92e03a9a750e37f018c54ae3946c7b3cb888c3
parent3de1b6c9a98993e6735098f94a7d5214d5fbcfcf

std.Io.Group: fix leak when wait is canceled

Only when the operation succeeds should the token field be set to null.

1 files changed, 5 insertions(+), 2 deletions(-)

lib/std/Io.zig+5-2
...@@ -1040,11 +1040,14 @@ pub const Group = struct {...@@ -1040,11 +1040,14 @@ pub const Group = struct {
10401040
1041 /// Blocks until all tasks of the group finish.1041 /// Blocks until all tasks of the group finish.
1042 ///1042 ///
1043 /// Idempotent. Not threadsafe.1043 /// On success, further calls to `wait`, `waitUncancelable`, and `cancel`
1044 /// do nothing.
1045 ///
1046 /// Not threadsafe.
1044 pub fn wait(g: *Group, io: Io) Cancelable!void {1047 pub fn wait(g: *Group, io: Io) Cancelable!void {
1045 const token = g.token orelse return;1048 const token = g.token orelse return;
1049 try io.vtable.groupWait(io.userdata, g, token);
1046 g.token = null;1050 g.token = null;
1047 return io.vtable.groupWait(io.userdata, g, token);
1048 }1051 }
10491052
1050 /// Equivalent to `wait` except uninterruptible.1053 /// Equivalent to `wait` except uninterruptible.