Bug 217236

Summary: Mac OS X: pthread_cond_wait reports still reachable leaked memory
Product: [Developer tools] valgrind Reporter: Evan Jones <evanj>
Component: memcheckAssignee: Julian Seward <jseward>
Status: RESOLVED FIXED    
Severity: normal CC: rhyskidd, tom
Priority: NOR    
Version: 3.6 SVN   
Target Milestone: ---   
Platform: Unlisted Binaries   
OS: macOS   
Latest Commit: Version Fixed In:
Sentry Crash Report:
Attachments: test program that causes the valgrind warning
corrected test program that causes the warning
add a suppression for new_sem_from_pool

Description Evan Jones 2009-12-03 18:10:22 UTC
Created attachment 38801 [details]
test program that causes the valgrind warning

On Mac OS X, pthread_cond_wait ends up calling new_sem_from_pool, which allocates a pool of semaphore objects that gets reused. This causes Valgrind to report a "still reachable" warning for this memory that is not leaked. Occasionally for more complex programs, this reports a full-blown "definitely lost" error. The attached program causes the SVN version of Valgrind to report this warning. The attached patch to the suppressions suppresses it.

The source of the new_sem_from_pool function can be found:

http://www.opensource.apple.com/source/Libc/Libc-583/pthreads/pthread.c
Comment 1 Evan Jones 2009-12-03 18:14:47 UTC
Created attachment 38802 [details]
corrected test program that causes the warning
Comment 2 Evan Jones 2009-12-03 18:16:36 UTC
Created attachment 38803 [details]
add a suppression for new_sem_from_pool
Comment 3 Evan Jones 2009-12-03 18:17:07 UTC
The original warning is:

=23593== 64 bytes in 1 blocks are still reachable in loss record 2 of 3
==23593==    at 0x15416: malloc (vg_replace_malloc.c:195)
==23593==    by 0x17225: realloc (vg_replace_malloc.c:476)
==23593==    by 0x229507: new_sem_from_pool (in /usr/lib/libSystem.B.dylib)
==23593==    by 0x2291A5: _pthread_cond_wait (in /usr/lib/libSystem.B.dylib)
==23593==    by 0x228DCC: pthread_cond_wait$UNIX2003 (in /usr/lib/libSystem.B.dylib)
==23593==    by 0x1E4A: main (in ./test)


The original suppression is:

{
   darwin-still-reachable-4
   Memcheck:Leak
   fun:malloc
   fun:realloc
   fun:new_sem_from_pool
   fun:_pthread_cond_wait
   fun:pthread_cond_wait$UNIX2003
   fun:main
}
Comment 4 Rhys Kidd 2015-05-07 13:21:21 UTC
Resolved in r15190 for OS X 10.8.