Skip to content

Commit 17a910a

Browse files
authored
sync: fix potential ThreadPool UAF
A race on join() was discovered. More info: kprotty/zap@97d4b4d
1 parent 43c7e4b commit 17a910a

File tree

1 file changed

+2
-6
lines changed

1 file changed

+2
-6
lines changed

src/ThreadPool.zig

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -335,12 +335,8 @@ fn unregister(noalias self: *ThreadPool, noalias maybe_thread: ?*Thread) void {
335335

336336
fn join(self: *ThreadPool) void {
337337
// Wait for the thread pool to be shutdown() then for all threads to enter a joinable state
338-
var sync: Sync = @bitCast(self.sync.load(.monotonic));
339-
if (!(sync.state == .shutdown and sync.spawned == 0)) {
340-
self.join_event.wait();
341-
sync = @bitCast(self.sync.load(.monotonic));
342-
}
343-
338+
self.join_event.wait();
339+
const sync: Sync = @bitCast(self.sync.load(.monotonic));
344340
assert(sync.state == .shutdown);
345341
assert(sync.spawned == 0);
346342

0 commit comments

Comments
 (0)