authorgravatar for 57794658+Littleote@users.noreply.github.comLittleote <57794658+Littleote@users.noreply.github.com> 2024-01-22 14:20:25+01:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2024-01-22 11:24:35-08:00
log3331c5e7af28bd2ee56a1080a1829e3fb6747f60
tree33b986b876fb5fc93e3e9609bc07bdd2d317c250
parentd0da3d731e40fe9e0b45d50d4c3bf8210b44d472

Free threads in std.Thread.Pool.init only with pool.join

Free the allocated threads in the initialization of a thread pool only with pool.join instead of additionally calling allocator.free causing free to be called twice. Resolves #18643

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

lib/std/Thread/Pool.zig+2-3
......@@ -35,10 +35,9 @@ pub fn init(pool: *Pool, options: Options) !void {
3535 }
3636
3737 const thread_count = options.n_jobs orelse @max(1, std.Thread.getCpuCount() catch 1);
38 pool.threads = try allocator.alloc(std.Thread, thread_count);
39 errdefer allocator.free(pool.threads);
4038
41 // kill and join any threads we spawned previously on error.
39 // kill and join any threads we spawned and free memory on error.
40 pool.threads = try allocator.alloc(std.Thread, thread_count);
4241 var spawned: usize = 0;
4342 errdefer pool.join(spawned);
4443