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

Only when the operation succeeds should the token field be set to null.
This commit is contained in:
Andrew Kelley 2025-10-27 16:59:31 -07:00
parent 3de1b6c9a9
commit c8739d6953

View File

@ -1040,11 +1040,14 @@ pub const Group = struct {
/// Blocks until all tasks of the group finish. /// Blocks until all tasks of the group finish.
/// ///
/// Idempotent. Not threadsafe. /// On success, further calls to `wait`, `waitUncancelable`, and `cancel`
/// do nothing.
///
/// Not threadsafe.
pub fn wait(g: *Group, io: Io) Cancelable!void { pub fn wait(g: *Group, io: Io) Cancelable!void {
const token = g.token orelse return; const token = g.token orelse return;
try io.vtable.groupWait(io.userdata, g, token);
g.token = null; g.token = null;
return io.vtable.groupWait(io.userdata, g, token);
} }
/// Equivalent to `wait` except uninterruptible. /// Equivalent to `wait` except uninterruptible.