Yo

On Thu, 2018-06-28 at 14:50 +0100, EML wrote:
> The program below creates two threads, in a detached state, and waits for 
> them to complete with 'pthread_exit'. Compile and run as:
> 
> > gcc -lpthread test.c
> > valgrind --leak-check=full a.out
> 
> valgrind-3.13.0 (compiled from source) reports no errors on some runs, and a 
> possible leak on other runs (560 bytes in 1 blocks), fairly randomly. On my 
> system, the ratio of error-free to bad runs is about 50/50.
> 
> Is this is a problem with valgrind, or my use of pthreads? Note that this 
> isn't the standard 'pthread_create' memory leak with joinable threads which 
> haven't been joined, since the threads are detached.  I'm compiling on Centos 
> 6.9, gcc 4.4.7. Thanks.

On my system, I systematically have the following possible leak:
==20923== 272 bytes in 1 blocks are possibly lost in loss record 1 of 1
==20923==    at 0x4C2DB70: calloc (vg_replace_malloc.c:711)
==20923==    by 0x4011EF1: allocate_dtv (dl-tls.c:322)
==20923==    by 0x401287D: _dl_allocate_tls (dl-tls.c:539)
==20923==    by 0x4E4100B: allocate_stack (allocatestack.c:580)
==20923==    by 0x4E4100B: pthread_create@@GLIBC_2.2.5 (pthread_create.c:539)
==20923==    by 0x108936: main (pth.c:19)

Assuming what you see is the same leak (always interesting to give the error
when you discuss an error :)), the possible leak disappears if I am adding
   sleep (10);
before
   pthread_exit(0);

So, it looks like pthread_exit (0) is executed in your case
when a detached thread has not yet cleaned up some of the memory
(the dtv array) used for its thread local storage.
And when this detached thread exits as the last one of the process,
no cleanup of this memory is done.

You can further investigate what happens by adding -v -v -v -d -d -d
and/or use some more options of memcheck to see what stack trace is releasing
this dtv memory when you add the sleep.

Philippe




------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Valgrind-users mailing list
Valgrind-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/valgrind-users

Reply via email to