title: Leaking memory with pthreads
body: <p>I'm using pthreads and according to valgrind I am leaking memory, like in <a href="https://stackoverflow.com/questions/5610677/valgrind-memory-leak-errors-when-using-pthread-create">valgrind memory leak errors when using pthread_create</a></p>
  
  <p>The top answer says that if you pthread_join all the threads this memory will be reclaimed, but it isn't for me.</p>
  
  <pre><code>pthread_t threads[NUM_THREADS];
  ...
  for (i = 0; i &lt; NUM_THREADS; i++) {
      pthread_create(&amp;threads[i], &amp;attr, Worker, NULL);
  }
  ...
  for (i = 0; i &lt; NUM_THREADS; i++) {
      pthread_join(threads[i], NULL);
  }
  </code></pre>
  
  <p>valgrind output</p>
  
  <pre><code>==2707== HEAP SUMMARY:
  ==2707==     in use at exit: 954 bytes in 4 blocks
  ==2707==   total heap usage: 7,717 allocs, 7,713 frees, 79,563 bytes allocated
  ==2707== 
  ==2707== 34 bytes in 1 blocks are still reachable in loss record 1 of 4
  ==2707==    at 0x402BE68: malloc (in /usr/lib/valgrind/vgpreload_memcheck-x86-linux.so)
  ==2707==    by 0x400541E: local_strdup (dl-load.c:162)
  ==2707==    by 0x40085D3: _dl_map_object (dl-load.c:2473)
  ==2707==    by 0x4012D5C: dl_open_worker (dl-open.c:225)
  ==2707==    by 0x400ECBE: _dl_catch_error (dl-error.c:178)
  ==2707==    by 0x4184D40: do_dlopen (dl-libc.c:89)
  ==2707==    by 0x404CD4B: start_thread (pthread_create.c:308)
  ==2707==    by 0x414BACD: clone (clone.S:130)
  ==2707== 
  ==2707== 34 bytes in 1 blocks are still reachable in loss record 2 of 4
  ==2707==    at 0x402BE68: malloc (in /usr/lib/valgrind/vgpreload_memcheck-x86-linux.so)
  ==2707==    by 0x400B05A: _dl_new_object (dl-object.c:161)
  ==2707==    by 0x4006437: _dl_map_object_from_fd (dl-load.c:1051)
  ==2707==    by 0x400839F: _dl_map_object (dl-load.c:2568)
  ==2707==    by 0x4012D5C: dl_open_worker (dl-open.c:225)
  ==2707==    by 0x400ECBE: _dl_catch_error (dl-error.c:178)
  ==2707==    by 0x4184D40: do_dlopen (dl-libc.c:89)
  ==2707==    by 0x404CD4B: start_thread (pthread_create.c:308)
  ==2707==    by 0x414BACD: clone (clone.S:130)
  ==2707== 
  ==2707== 256 bytes in 1 blocks are still reachable in loss record 3 of 4
  ==2707==    at 0x402A5E6: calloc (in /usr/lib/valgrind/vgpreload_memcheck-x86-linux.so)
  ==2707==    by 0x401045C: _dl_check_map_versions (dl-version.c:300)
  ==2707==    by 0x401336A: dl_open_worker (dl-open.c:268)
  ==2707==    by 0x400ECBE: _dl_catch_error (dl-error.c:178)
  ==2707==    by 0x4184D40: do_dlopen (dl-libc.c:89)
  ==2707==    by 0x404CD4B: start_thread (pthread_create.c:308)
  ==2707==    by 0x414BACD: clone (clone.S:130)
  ==2707== 
  ==2707== 630 bytes in 1 blocks are still reachable in loss record 4 of 4
  ==2707==    at 0x402A5E6: calloc (in /usr/lib/valgrind/vgpreload_memcheck-x86-linux.so)
  ==2707==    by 0x400AE0F: _dl_new_object (dl-object.c:77)
  ==2707==    by 0x4006437: _dl_map_object_from_fd (dl-load.c:1051)
  ==2707==    by 0x400839F: _dl_map_object (dl-load.c:2568)
  ==2707==    by 0x4012D5C: dl_open_worker (dl-open.c:225)
  ==2707==    by 0x400ECBE: _dl_catch_error (dl-error.c:178)
  ==2707==    by 0x4184D40: do_dlopen (dl-libc.c:89)
  ==2707==    by 0x404CD4B: start_thread (pthread_create.c:308)
  ==2707==    by 0x414BACD: clone (clone.S:130)
  ==2707== 
  ==2707== LEAK SUMMARY:
  ==2707==    definitely lost: 0 bytes in 0 blocks
  ==2707==    indirectly lost: 0 bytes in 0 blocks
  ==2707==      possibly lost: 0 bytes in 0 blocks
  ==2707==    still reachable: 954 bytes in 4 blocks
  ==2707==         suppressed: 0 bytes in 0 blocks
  ==2707== 
  ==2707== For counts of detected and suppressed errors, rerun with: -v
  ==2707== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)
  </code></pre>
  
  <p>Am I doing something wrong or is the top answer incorrect?</p>