]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
fix unlock and return code. Fixes #4862
authorAlan T. DeKok <aland@freeradius.org>
Thu, 26 Jan 2023 13:59:23 +0000 (08:59 -0500)
committerAlan T. DeKok <aland@freeradius.org>
Thu, 26 Jan 2023 14:01:12 +0000 (09:01 -0500)
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

src/lib/util/atexit.h

index 020b4775ef4426fc892c6b5958747f96fc76e687..b04b8f2e1185bda3b3500a38854cc779155bae4c 100644 (file)
@@ -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