From: Alan T. DeKok Date: Thu, 26 Jan 2023 13:59:23 +0000 (-0500) Subject: fix unlock and return code. Fixes #4862 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=c26f4fb9ba47f3538d766770a17ab4e40a07eb4a;p=thirdparty%2Ffreeradius-server.git fix unlock and return code. Fixes #4862 Don't override an error return code with a successful one. Instead, set the success code first, and then override it if there's an error. Now that that's cleaned up, always unlock the mutex --- diff --git a/src/lib/util/atexit.h b/src/lib/util/atexit.h index 020b4775ef4..b04b8f2e118 100644 --- a/src/lib/util/atexit.h +++ b/src/lib/util/atexit.h @@ -129,19 +129,17 @@ static inline int fr_atexit_talloc_free(void *to_free) static atomic_bool _init_done = false; \ static pthread_mutex_t _init_mutex = PTHREAD_MUTEX_INITIALIZER; \ void *_our_uctx = _uctx; /* stop _uctx being evaluated multiple times, it may be a call to malloc() */ \ + *(_ret) = 0; \ if (unlikely(!atomic_load(&_init_done))) { \ pthread_mutex_lock(&_init_mutex); \ if (!atomic_load(&_init_done)) { \ if (_fr_atexit_global_once_funcs(_init, _free, _our_uctx) < 0) { \ *(_ret) = -1; \ - pthread_mutex_unlock(&_init_mutex); \ } \ atomic_store(&_init_done, true); \ - } else { \ - pthread_mutex_unlock(&_init_mutex); \ } \ + pthread_mutex_unlock(&_init_mutex); \ } \ - *(_ret) = 0; \ } /** Setup pair of global init/free functions