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)
This commit is contained in:
parent
4eed5f9af1
commit
67fb39b808
|
@ -76,14 +76,15 @@ thread_spawn(ThreadEntry entry, ThreadResult error_result)
|
||||||
pthread_t handle;
|
pthread_t handle;
|
||||||
int error;
|
int error;
|
||||||
if (!new_uninitialized(&th)) {
|
if (!new_uninitialized(&th)) {
|
||||||
|
free(native_arg);
|
||||||
return THREAD_NONE;
|
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) {
|
if (error) {
|
||||||
errno = error;
|
errno = error;
|
||||||
|
free(native_arg);
|
||||||
return delete_handle(th);
|
return delete_handle(th);
|
||||||
}
|
}
|
||||||
assert(handle && "System allows 0 as thread id");
|
|
||||||
initialize_handle(&th, handle);
|
initialize_handle(&th, handle);
|
||||||
return th;
|
return th;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue