<div dir="ltr"><div>Hi PETSc devs,</div><div><br></div><div>I have a C++ program written with PETSc (code available at <a href="https://github.com/DiffeoInvariant/NLTS/blob/master/examples/mutual_opt.cpp">https://github.com/DiffeoInvariant/NLTS/blob/master/examples/mutual_opt.cpp</a>), and if I run it with -malloc_debug and -malloc_dump enabled, PETSc says no memory is left unfreed at exit. However, running with valgrind --leak-check=full --show-leak-kinds=all gives me this leak summary: </div><div><br></div><div>LEAK SUMMARY:<br>==15364==    definitely lost: 0 bytes in 0 blocks<br>==15364==    indirectly lost: 0 bytes in 0 blocks<br>==15364==      possibly lost: 0 bytes in 0 blocks<br>==15364==    still reachable: 610,904 bytes in 8,246 blocks<br>==15364==         suppressed: 0 bytes in 0 blocks</div><div><br></div><div>The information from --show-leak-kinds=all gives several blocks of the form (this is the last block printed; I've attached the full output from valgrind to this email)</div><div><br></div><div>==15364== 329,080 bytes in 3 blocks are still reachable in loss record 7 of 7<br>==15364==    at 0x483CFAF: realloc (in /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so)<br>==15364==    by 0x7BDE1A7: ??? (in /usr/lib/x86_64-linux-gnu/libpciaccess.so.0.11.1)<br>==15364==    by 0x7BDE41C: ??? (in /usr/lib/x86_64-linux-gnu/libpciaccess.so.0.11.1)<br>==15364==    by 0x7BDE579: pci_device_get_device_name (in /usr/lib/x86_64-linux-gnu/libpciaccess.so.0.11.1)<br>==15364==    by 0x759CFC4: hwloc_look_pci (in /usr/local/petsc/arch-linux-cxx-debug/lib/libmpi.so.12.1.8)<br>==15364==    by 0x7571D0B: hwloc_discover (in /usr/local/petsc/arch-linux-cxx-debug/lib/libmpi.so.12.1.8)<br>==15364==    by 0x7571637: hwloc_topology_load (in /usr/local/petsc/arch-linux-cxx-debug/lib/libmpi.so.12.1.8)<br>==15364==    by 0x736780A: MPIR_Init_thread (in /usr/local/petsc/arch-linux-cxx-debug/lib/libmpi.so.12.1.8)<br>==15364==    by 0x7367435: PMPI_Init_thread (in /usr/local/petsc/arch-linux-cxx-debug/lib/libmpi.so.12.1.8)<br>==15364==    by 0x491CABA: PetscInitialize (in /usr/local/petsc/arch-linux-cxx-debug/lib/libpetsc.so.3.012.4)<br>==15364==    by 0x724AB0E: nlts::io::Initialize(int*, char***, char const*, char const*) (io.cpp:126)<br>==15364==    by 0x4023CB: main (mutual_opt.cpp:30)</div><div><br></div><div>The function nlts::io::Initialize that's referenced at the bottom is simply</div><div><br></div><div><table class="gmail-highlight gmail-tab-size gmail-js-file-line-container"><tbody><tr><td id="gmail-LC121" class="gmail-blob-code gmail-blob-code-inner gmail-js-file-line">PetscErrorCode <span class="gmail-pl-en">nlts::io::Initialize</span>(<span class="gmail-pl-k">int</span> *argc, <span class="gmail-pl-k">char</span> ***argv,</td>
      </tr>
      <tr>
        </tr></tbody></table><table class="gmail-highlight gmail-tab-size gmail-js-file-line-container"><tbody><tr><td id="gmail-LC122" class="gmail-blob-code gmail-blob-code-inner gmail-js-file-line">                             <span class="gmail-pl-k">const</span> <span class="gmail-pl-k">char</span> file[],</td>
      </tr>
      <tr>
        </tr></tbody></table><table class="gmail-highlight gmail-tab-size gmail-js-file-line-container"><tbody><tr><td id="gmail-LC123" class="gmail-blob-code gmail-blob-code-inner gmail-js-file-line">                             <span class="gmail-pl-k">const</span> <span class="gmail-pl-k">char</span> help[])</td>
      </tr>
      <tr>
        </tr></tbody></table><table class="gmail-highlight gmail-tab-size gmail-js-file-line-container"><tbody><tr><td id="gmail-LC124" class="gmail-blob-code gmail-blob-code-inner gmail-js-file-line">    {</td>
      </tr>
      <tr>
        </tr></tbody></table><table class="gmail-highlight gmail-tab-size gmail-js-file-line-container"><tbody><tr><td id="gmail-LC125" class="gmail-blob-code gmail-blob-code-inner gmail-js-file-line">      PetscFunctionBeginUser;</td>
      </tr>
      <tr>
        </tr></tbody></table><table class="gmail-highlight gmail-tab-size gmail-js-file-line-container"><tbody><tr><td id="gmail-LC126" class="gmail-blob-code gmail-blob-code-inner gmail-js-file-line">      <span class="gmail-pl-k">auto</span> ierr = <span class="gmail-pl-c1">PetscInitialize</span>(argc, argv, file, help);<span class="gmail-pl-c1">CHKERRQ</span>(ierr);</td>
      </tr>
      <tr>
        </tr></tbody></table><table class="gmail-highlight gmail-tab-size gmail-js-file-line-container"><tbody><tr><td id="gmail-LC127" class="gmail-blob-code gmail-blob-code-inner gmail-js-file-line">      <span class="gmail-pl-c1">PetscFunctionReturn</span>(ierr);</td>
      </tr>
      <tr>
        </tr></tbody></table>    }</div><div><br></div><div>Is valgrind actually detecting unfreed memory here, or is this something I don't need to worry about?</div><div><br></div><div>Thanks!</div><div><br></div><div>-Zane Jakobs<br></div></div>