From 67fb39b808d0bbe56d80939664feb40b99460b9e Mon Sep 17 00:00:00 2001 From: Vftdan Date: Thu, 24 Oct 2024 10:23:51 +0200 Subject: [PATCH] Fix thread.posix.c - Fix memory leak when thread_spawn fails - Remove incorrect assertion (pthread_t in general case is neither scalar nor non-zero) --- src/common/util/thread.posix.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/common/util/thread.posix.c b/src/common/util/thread.posix.c index 8c4ce9d..bdaa1b1 100644 --- a/src/common/util/thread.posix.c +++ b/src/common/util/thread.posix.c @@ -76,14 +76,15 @@ thread_spawn(ThreadEntry entry, ThreadResult error_result) pthread_t handle; int error; if (!new_uninitialized(&th)) { + free(native_arg); return THREAD_NONE; } - error = pthread_create(&handle, NULL, &run_entry, native_arg); + error = pthread_create(&handle, NULL, &run_entry, native_arg); // calls free(native_arg) if error == 0 if (error) { errno = error; + free(native_arg); return delete_handle(th); } - assert(handle && "System allows 0 as thread id"); initialize_handle(&th, handle); return th; }