Search code examples
memory-leaksvalgrindhdf5

Valgrind is not detecting HDF5 leaked resources


I have noticed that Valgrind is not detecting resources created with the C API of HDF5 and that are not closed before the end of the program, though I launched it with the option --leak-check=full. Is that normal ?

I often rely on Valgrind before shipping the code, but today I was surprised and frustrated when reviewing the code that it was not detected by it.


Solution

  • valgrind memcheck tool detects memory allocated/released by the 'standard' allocators, such as malloc/free/new/delete/...

    If the C API of HDF5 is not using (internally) the above standard allocators, then there is no way that valgrind could guess by itself what to monitor.

    If HDF5 is implementing its own heap management (e.g.based on mmap, and cutting these blocks in smaller allocated blocks), then valgrind provides 'client requests' allowing to have some valgrind support for such non standard allocators. But that all implies some work in the HDF5 sources.

    See e.g. http://www.valgrind.org/docs/manual/mc-manual.html#mc-manual.mempools for more information about how to describe such non standard allocators.

    Some libraries/tools that are implementing their own non standard allocators have sometime a way (e.g. an environment variable) to indicate to bypass these non standard allocators, and still use malloc/free/... Again, up to HDF5 to provide this.

    If now HDF5 really uses the standard allocators and valgrind cannot track what it does, then file a bug on valgrind bugzilla.