[Bug 200138] [PATCH] Fixed race condition incurred in libthr by some foreign malloc libraries
bugzilla-noreply at freebsd.org
bugzilla-noreply at freebsd.org
Tue May 12 02:08:54 UTC 2015
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=200138
Bug ID: 200138
Summary: [PATCH] Fixed race condition incurred in libthr by
some foreign malloc libraries
Product: Base System
Version: 10.1-STABLE
Hardware: Any
OS: Any
Status: New
Keywords: patch
Severity: Affects Only Me
Priority: ---
Component: threads
Assignee: freebsd-threads at FreeBSD.org
Reporter: yuri at rawbw.com
Keywords: patch
Created attachment 156674
--> https://bugs.freebsd.org/bugzilla/attachment.cgi?id=156674&action=edit
patch
While investigating the message coming from "Thread %p has exited with %d
leftover", I found that _pthread_setspecific is entered twice with the same
TCB, _get_curthread() returned the same thread pointer. Second invocation was
incurred by the google tcmalloc library (devel/google-perftools port).
> (gdb) bt
> #0 yuri_enter (serno=60) at /usr/src/lib/libthr/thread/thr_spec.c:60
> #1 0x0000000804e23e89 in _pthread_setspecific (userkey=3, value=0x740a080) at /usr/src/lib/libthr/thread/thr_spec.c:228
> #2 0x000000080408b95c in ?? () from /usr/local/lib/qt4/libQtCore.so.4
> #3 0x0000000804e1da3a in thread_start (curthread=0x73f6800) at /usr/src/lib/libthr/thread/thr_create.c:288
> #4 0x0000000000000000 in ?? ()
> Backtrace stopped: Cannot access memory at address 0x7fffdf9fb000
> (gdb) bt
> #0 yuri_enter (serno=61) at /usr/src/lib/libthr/thread/thr_spec.c:60
> #1 0x0000000804e23e89 in _pthread_setspecific (userkey=2, value=0x7a9520) at /usr/src/lib/libthr/thread/thr_spec.c:228
> #2 0x00000008008ff4de in perftools_pthread_setspecific(int, void*) () from /usr/local/lib/libtcmalloc.so.4
> #3 0x00000008008f2322 in tcmalloc::ThreadCache::CreateCacheIfNecessary() () from /usr/local/lib/libtcmalloc.so.4
> #4 0x00000008008ea666 in ?? () from /usr/local/lib/libtcmalloc.so.4
> #5 0x00000008008ffd92 in tc_calloc () from /usr/local/lib/libtcmalloc.so.4
> #6 0x0000000804e243a1 in pthread_key_allocate_data () at /usr/src/lib/libthr/thread/thr_spec.c:212
> #7 0x0000000804e23f19 in _pthread_setspecific (userkey=3, value=0x740a080) at /usr/src/lib/libthr/thread/thr_spec.c:231
> #8 0x000000080408b95c in ?? () from /usr/local/lib/qt4/libQtCore.so.4
> #9 0x0000000804e1da3a in thread_start (curthread=0x73f6800) at /usr/src/lib/libthr/thread/thr_create.c:288
> #10 0x0000000000000000 in ?? ()
This causes some memory loss, and stray message about leftover TLS data.
The attached patch corrects for such potential problem by double-checking the
pthread's "specific" array after allocating it, and frees the newly allocated
copy if it happens to be already allocated.
Please keep the comment, because I think these lines may appear very confusing
and wrong to people without the knowledge of this specific situation.
--
You are receiving this mail because:
You are the assignee for the bug.
More information about the freebsd-threads
mailing list