]> git.ipfire.org Git - thirdparty/freeradius-server.git/commit
atexit: skip TLS-cached pools once shutdown has freed them developer/arr2036 master
authorArran Cudbard-Bell <a.cudbardb@freeradius.org>
Mon, 27 Apr 2026 18:01:35 +0000 (14:01 -0400)
committerArran Cudbard-Bell <a.cudbardb@freeradius.org>
Mon, 27 Apr 2026 19:52:46 +0000 (15:52 -0400)
commit0d90b4d29db3e9086e193001f8412163eb80bb70
tree8967c05f6b49d5b229d852d401abaf3a9ec6ad8c
parentf3d4c64b48227ee53ca4074f80fbc405537bfdeb
atexit: skip TLS-cached pools once shutdown has freed them

`fr_atexit_thread_trigger_all()` runs each registered thread destructor
on the calling (main) thread, including ones that free `_Thread_local`
caches owned by threads outside our schedule (librdkafka's bg threads,
perl, etc.).  We can free their pool chunks but can't reset another
thread's TLS slot, so the next call from those threads dereferences a
dangling pointer and aborts with "Bad talloc magic value" - first seen
in `_kafka_log_cb` from the "Terminating instance" debug line emitted
inside `rd_kafka_destroy()` during `mod_detach`.

Add `fr_atexit_thread_local_disable_alloc()` / ..._alloc_disabled()` in
atexit.c as the single source of truth, called once from radiusd
*before* the trigger.  TLS-pool initialisers consult it before reading
their slot and fall back to `talloc_*(NULL, ...)` when set:

  - log.c:fr_log_pool_init returns NULL
  - sbuff.c:sbuff_scratch_init returns NULL

Other TLS pools registered the same way (md4/md5/hmac_*, strerror,
talloc autofree) can opt in as crashes surface; the single flag means
the fix is one extra check at the top of each initialiser.
src/lib/util/atexit.c
src/lib/util/atexit.h
src/lib/util/log.c
src/lib/util/sbuff.c