Skip Menu |
 

From: ghudson@mit.edu
Subject: git commit
Download (untitled) / with headers
text/plain 1.3KiB

Block library unloading to avoid finalizer races

Library finalizers can run due to the library being unloaded or the
process exiting. If the library is being unloaded, global memory
resources must be released to avoid memory leaks. But if the process
is exiting, releasing memory resources can lead to race conditions if
another thread invokes functions from the library during or after
finalizer execution. Most commonly this manifests as an assertion
error about trying to lock a destroyed mutex.

We can block unloading of our library on ELF platforms by passing "-z
nodelete" to the linker. Add a shell variable "lib_unload_prevented"
to the shlib.conf outputs, set it on platforms where we can block
unloading, and suppress finalizers when it is set.

On Windows we can detect if the process is exiting by checking for a
non-null lpvReserved argument in DllMain(). Do not execute finalizers
when the process is executing.

https://github.com/krb5/krb5/commit/1bfcf572241a4ec0e44e609e5c6b7c0b11b08eea
Author: Greg Hudson <ghudson@mit.edu>
Commit: 1bfcf572241a4ec0e44e609e5c6b7c0b11b08eea
Branch: master
src/aclocal.m4 | 3 +++
src/config/shlib.conf | 34 +++++++++++++++++++++++-----------
src/include/k5-platform.h | 5 ++++-
src/lib/win_glue.c | 6 +++++-
4 files changed, 35 insertions(+), 13 deletions(-)