title: Valgrind debug logs for linux
body: <p>Goal:</p>
  <ol>
  <li>Hi, I am new to valgrind and I need to run the valgrind on our existing code to check the memory leaks if any.</li>
  </ol>
  <p>Result and problem:</p>
  <ol>
  <li>I have one daemon running in backend which invoke multiple processes and which will never stop and scan the files. I have run the valgrind command on main daemon.</li>
  <li>In another terminal I have test one scenario to get the logs and now I try to stop the valgrind by pressing ctrl+c and it will stop and give me the result of memory leak.</li>
  <li>When I try to stop the valgrind/daemon by sending signal to daemon it will stop but not give me the proper logs.</li>
  </ol>
  <p>Below is the example:
  Press ctrl+c</p>
  <pre><code>==47030==    at 0x4C2FB0F: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
  ==47030==    by 0x6A1765D: IsSymbolicLink(char const*, stat, char*) (misc.cpp:352)
  ==47030==    by 0x6A28DCF: HandleEvents(int, Filter&amp;) (rtsysitf.cpp:3639)
  ==47030==    by 0x6A25A63: ProcessMessage(void*, unsigned long const*) (rtsysitf.cpp:169)
  ==47030==    by 0x6A05AD5: CEventThreadpool::eventsDispatchThreadProc(void*) (EventsThreadpool.cpp:547)
  ==47030==    by 0x5BA46DA: start_thread (pthread_create.c:463)
  ==47030==    by 0x5EDDA3E: clone (clone.S:95)
  </code></pre>
  <p><strong>IsSymbolicLink is the function in which I have written a code of memory leak for testing purpose and I got that in debug log when pressing ctrl+c</strong></p>
  <p><strong>Also here I got 1000+ memory leaks in report which is not valid because allocating memory in constructor and deallocate it in destructor and pressing ctrl+c will never reach to destructor.</strong></p>
  <p>When stop the daemon by : ./opssvc -stop</p>
  <pre><code>==25622== 32 bytes in 1 blocks are still reachable in loss record 2 of 24
  ==25622==    at 0x4C2FB0F: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
  ==25622==    by 0x4016077: _dl_close_worker.part.0 (dl-close.c:395)
  ==25622==    by 0x4016AF9: _dl_close_worker (dl-close.c:125)
  ==25622==    by 0x4016AF9: _dl_close (dl-close.c:842)
  ==25622==    by 0x5F2351E: _dl_catch_exception (dl-error-skeleton.c:196)
  ==25622==    by 0x5F235AE: _dl_catch_error (dl-error-skeleton.c:215)
  ==25622==    by 0x4E3D744: _dlerror_run (dlerror.c:162)
  ==25622==    by 0x4E3D0B2: dlclose (dlclose.c:46)
  ==25622==    by 0x407FFF: main (opssvc.cpp:457)
  ==25622==
  ==25622== 33 bytes in 1 blocks are still reachable in loss record 3 of 24
  ==25622==    at 0x4C2FB0F: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
  ==25622==    by 0x400C437: _dl_new_object (dl-object.c:163)
  ==25622==    by 0x40069C4: _dl_map_object_from_fd (dl-load.c:943)
  ==25622==    by 0x400904B: _dl_map_object (dl-load.c:2389)
  ==25622==    by 0x400E361: openaux (dl-deps.c:63)
  ==25622==    by 0x5F2351E: _dl_catch_exception (dl-error-skeleton.c:196)
  ==25622==    by 0x400E667: _dl_map_object_deps (dl-deps.c:249)
  ==25622==    by 0x4014F98: dl_open_worker (dl-open.c:278)
  ==25622==    by 0x5F2351E: _dl_catch_exception (dl-error-skeleton.c:196)
  ==25622==    by 0x4014819: _dl_open (dl-open.c:605)
  ==25622==    by 0x4E3CF95: dlopen_doit (dlopen.c:66)
  ==25622==    by 0x5F2351E: _dl_catch_exception (dl-error-skeleton.c:196)
  </code></pre>
  <p><strong>When I stop the program in this way, I didn't get the log for the IsSymbolicLink function and got logs only for Dynamic libraries</strong></p>
  <p>I have run the below command to check the valgrind:</p>
  <p>valgrind --leak-check=full --track-origins=yes --show-leak-kinds=all --error-limit=no --trace-children=yes --log-file=&quot;/tmp/valgrind_log.log&quot; ./opssvc</p>
  <p>Can someone please help me to resolve this.</p>