From: Joseph Sutton Date: Tue, 10 Jan 2023 00:06:25 +0000 (+1300) Subject: lib/tfork: Don't overwrite 'ret' in cleanup phase X-Git-Tag: talloc-2.4.0~31 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=cbe6fb38ec13adbe06667f16241d61d4e2a80545;p=thirdparty%2Fsamba.git lib/tfork: Don't overwrite 'ret' in cleanup phase The cleanup phase of tfork_create() saves errno prior to calling functions that might modify it, with the intention of restoring it afterwards. However, the value of 'ret' is accidentally overwritten. It will always be equal to 0, and hence errno will not be restored. Fix this by introducing a new variable, ret2, for calling functions in the cleanup phase. Signed-off-by: Joseph Sutton Reviewed-by: Jeremy Allison --- diff --git a/lib/util/tfork.c b/lib/util/tfork.c index 9867543702e..57a4e18638b 100644 --- a/lib/util/tfork.c +++ b/lib/util/tfork.c @@ -739,8 +739,9 @@ struct tfork *tfork_create(void) struct tfork_state *state = NULL; struct tfork *t = NULL; pid_t pid; - int saved_errno; + int saved_errno = 0; int ret = 0; + int ret2; #ifdef HAVE_PTHREAD ret = pthread_once(&tfork_global_is_initialized, @@ -816,16 +817,16 @@ cleanup: close(t->event_fd); } - ret = tfork_create_reap_waiter(state->waiter_pid); - assert(ret == 0); + ret2 = tfork_create_reap_waiter(state->waiter_pid); + assert(ret2 == 0); free(t); t = NULL; } } - ret = tfork_uninstall_sigchld_handler(); - assert(ret == 0); + ret2 = tfork_uninstall_sigchld_handler(); + assert(ret2 == 0); tfork_global_free();