From: Arran Cudbard-Bell Date: Fri, 12 Feb 2021 21:07:30 +0000 (+0000) Subject: Allow disarming of atexit thread-local destructors X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=3fa2ebffdcbb1a4ed92826b1719ad484af40999a;p=thirdparty%2Ffreeradius-server.git Allow disarming of atexit thread-local destructors --- diff --git a/src/lib/util/thread_local.c b/src/lib/util/thread_local.c index 3671140a146..afea1837388 100644 --- a/src/lib/util/thread_local.c +++ b/src/lib/util/thread_local.c @@ -221,3 +221,25 @@ int fr_thread_local_atexit(fr_thread_local_atexit_t func, void const *uctx) return 0; } +/** Remove destructor + * + * @return + * - 0 on success. + * - -1 if function and uctx could not be found. + */ +int fr_thread_local_atexit_disarm(fr_thread_local_atexit_t func, void const *uctx) +{ + fr_exit_handler_entry_t *e = NULL; + + while ((e = fr_dlist_next(&thread_local_atexit->head, e))) { + if ((e->func == func) && (e->uctx == uctx)) { + fr_dlist_remove(&thread_local_atexit->head, e); + talloc_set_destructor(e, NULL); + talloc_free(e); + return 0; + } + } + + return -1; +} + diff --git a/src/lib/util/thread_local.h b/src/lib/util/thread_local.h index c3adab35134..308bc1fda1d 100644 --- a/src/lib/util/thread_local.h +++ b/src/lib/util/thread_local.h @@ -42,6 +42,8 @@ int fr_thread_local_atexit_setup(void); int fr_thread_local_atexit(fr_thread_local_atexit_t func, void const *uctx); +int fr_thread_local_atexit_disarm(fr_thread_local_atexit_t func, void const *uctx); + /** Set a destructor for thread local storage to free the memory on thread exit * * @note Pointers to thread local storage seem to become unusable as threads are