Fix one of the TODO items when creating a new thread: release the copied cpu and free the task state.
Signed-off-by: Warner Losh <[email protected]> --- Free the new task state and drop references to copied cpu structure when pthread_create failes. --- linux-user/syscall.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/linux-user/syscall.c b/linux-user/syscall.c index d3d9fffb54..7b2e32bcf5 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -7005,7 +7005,6 @@ static int do_fork(CPUArchState *env, unsigned int flags, abi_ulong newsp, cpu->random_seed = qemu_guest_random_seed_thread_part1(); ret = pthread_create(&info.thread, &attr, clone_func, &info); - /* TODO: Free new CPU state if thread creation failed. */ sigprocmask(SIG_SETMASK, &info.sigmask, NULL); pthread_attr_destroy(&attr); @@ -7014,7 +7013,10 @@ static int do_fork(CPUArchState *env, unsigned int flags, abi_ulong newsp, pthread_cond_wait(&info.cond, &info.mutex); ret = info.tid; } else { - ret = -1; + ret = -host_to_target_errno(ret); + object_unparent(OBJECT(new_cpu)); + object_unref(OBJECT(new_cpu)); + g_free(ts); } pthread_mutex_unlock(&info.mutex); pthread_cond_destroy(&info.cond); --- base-commit: ac0cc20ad2fe0b8df2e5d9458e90a095ac711ab1 change-id: 20260507-linux-user-bug-6a5e4524d2db Best regards, -- Warner Losh <[email protected]>
