diff options
author | Rich Felker <dalias@aerifal.cx> | 2020-11-10 14:29:05 -0500 |
---|---|---|
committer | Rich Felker <dalias@aerifal.cx> | 2020-11-11 10:54:58 -0500 |
commit | cbecda0b506c7d49a2f7fe3dc44e0e3dcf663764 (patch) | |
tree | f6aaefddc91ac739a8c8bae6426ba7a5758a45c7 /src/malloc/lite_malloc.c | |
parent | 4ffa7068993ab4a1e1cedfed8954db979d9b7fbd (diff) | |
download | musl-cbecda0b506c7d49a2f7fe3dc44e0e3dcf663764.tar.gz musl-cbecda0b506c7d49a2f7fe3dc44e0e3dcf663764.tar.bz2 musl-cbecda0b506c7d49a2f7fe3dc44e0e3dcf663764.tar.xz musl-cbecda0b506c7d49a2f7fe3dc44e0e3dcf663764.zip |
dlerror: don't gratuitously hold freebuf_queue lock while freeing
thread-local buffers allocated for dlerror need to be queued for free
at a later time when the owning thread exits, since malloc may be
replaced by application code and the exiting context is not valid to
call application code from. the code to process queue of pending
frees, introduced in commit aa5a9d15e09851f7b4a1668e9dbde0f6234abada,
gratuitously held the lock for the entire duration of queue
processing, updating the global queue pointer after each free, despite
there being no logical requirement that all frees finish before
another thread can access the queue.
instead, immediately claim the whole queue for freeing and release the
lock, then walk the list and perform frees without the lock held. the
change is unlikely to make any meaningful difference to performance,
but it eliminates one point where the allocator is called under an
internal lock. since the allocator may be application-provided, such
calls are undesirable because they allow application code to impede
forward progress of libc functions in other threads arbitrarily long,
and to induce deadlock if it calls a libc function that requires the
same lock.
the change also eliminates a lock ordering consideration that's an
impediment upcoming work with multithreaded fork.
Diffstat (limited to 'src/malloc/lite_malloc.c')
0 files changed, 0 insertions, 0 deletions