When pthread_create fails in do_freebsd_thr_new, the allocated TaskState and CPU created by cpu_copy were leaked. Clean them up using the same object_unparent/object_unref pattern used by thr_exit, and free the TaskState with g_free.
Signed-off-by: Warner Losh <[email protected]> --- bsd-user/freebsd/os-thread.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/bsd-user/freebsd/os-thread.c b/bsd-user/freebsd/os-thread.c index 1d88ee05e4..9e6055a040 100644 --- a/bsd-user/freebsd/os-thread.c +++ b/bsd-user/freebsd/os-thread.c @@ -1633,7 +1633,6 @@ abi_long do_freebsd_thr_new(CPUArchState *env, sigprocmask(SIG_BLOCK, &sigmask, &info.sigmask); ret = pthread_create(&info.thread, &attr, new_freebsd_thread_start, &info); - /* XXX Free new CPU state if thread creation fails. */ sigprocmask(SIG_SETMASK, &info.sigmask, NULL); pthread_attr_destroy(&attr); @@ -1642,6 +1641,9 @@ abi_long do_freebsd_thr_new(CPUArchState *env, pthread_cond_wait(&info.cond, &info.mutex); } else { /* Creation of new thread failed. */ + object_unparent(OBJECT(new_cpu)); + object_unref(OBJECT(new_cpu)); + g_free(ts); ret = -host_to_target_errno(errno); } -- 2.52.0
