As a side question, when you use threads, do you join them from the thread who created them? Or, do you create them in detached mode? Here are some hints:
http://stackoverflow.com/questions/5610 … ead-create
Read the first response. In my case, I use option number 2: "Detach your thread after creation (by calling pthread_detach)"
That makes valgrind happy and gives me this:
==4033== HEAP SUMMARY:
==4033== in use at exit: 0 bytes in 0 blocks
==4033== total heap usage: 51 allocs, 51 frees, 6,995 bytes allocated
==4033==
==4033== All heap blocks were freed -- no leaks are possible
==4033==
==4033== For counts of detected and suppressed errors, rerun with: -v
==4033== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 2 from 2)
Without it, I get this:
==4141== HEAP SUMMARY:
==4141== in use at exit: 2,304 bytes in 8 blocks
==4141== total heap usage: 51 allocs, 43 frees, 6,995 bytes allocated
==4141==
==4141== 2,304 bytes in 8 blocks are possibly lost in loss record 1 of 1
==4141== at 0x4C29DB4: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==4141== by 0x4012074: _dl_allocate_tls (dl-tls.c:297)
==4141== by 0x5468ABC: pthread_create@@GLIBC_2.2.5 (allocatestack.c:571)
==4141== by 0x504544F: ems::threading::pthread::Thread::Start() (thread.cpp:39)
==4141== by 0x50467A1: ems::threading::WorkerPool::Initialize(unsigned int) (workerpool.cpp:51)
==4141== by 0x525A64C: ems::net::BaseSocketReactor::Initialize(unsigned int) (basesocketreactor.cpp:42)
==4141== by 0x4011CE: main (main.cpp:28)
==4141==
==4141== LEAK SUMMARY:
==4141== definitely lost: 0 bytes in 0 blocks
==4141== indirectly lost: 0 bytes in 0 blocks
==4141== possibly lost: 2,304 bytes in 8 blocks
==4141== still reachable: 0 bytes in 0 blocks
==4141== suppressed: 0 bytes in 0 blocks
==4141==
==4141== For counts of detected and suppressed errors, rerun with: -v
==4141== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 2 from 2)