Page tree


False valgrind errors with HDF5

I get the following valgrind (3.1.0) complaint:

  ==24788== Syscall param write(buf) points to uninitialised byte(s)
  ==24788==    at 0x40007F2: (within /lib/ld-2.6.1.so)
  ==24788==    by 0x434FC52: write (in /lib/i686/cmov/libc-2.6.1.so)
  ==24788==    by 0x408E28B: H5FD_sec2_write (in /home/domel/pack/i686/lib/libhdf5.so.0.0.0)
  ==24788==  Address 0x4443170 is 440 bytes inside a block of size 1,864 alloc'd
  ==24788==    at 0x4024765: malloc (vg_replace_malloc.c:149)
  ==24788==    by 0x4092B6A: H5FL_malloc (in /home/domel/pack/i686/lib/libhdf5.so.0.0.0)
  

On simply opening a file and closing it:

        hid_t file = H5Fcreate("test.h5", H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
        herr_t status = H5Fclose(file);
        return 0;

I get a small memory leak on simply creating a group:

hid_t group = H5Gcreate(file, gname.c_str (), 0);
herr_t status = H5Gclose(group);
  
==24788== ERROR SUMMARY: 2 errors from 1 contexts (suppressed: 21 from 1)
==24788== malloc/free: in use at exit: 16 bytes in 2 blocks. ==24788== malloc/free: 1,115 allocs, 1,113 frees, 454,594 bytes allocated. ==24788== For counts of detected errors, rerun with: -v ==24788== searching for pointers to 2 not-freed blocks. ==24788== checked 133,708 bytes.

Answer:

The HDF5 library has internal free lists of memory structures, which can confuse memory allocation checking tools like valgrind and Purify. Also, in HDF5-1.6, HDF5 was writing out "known empty, but uninitialized" portions of memory, which cause memory checkers to complain.

If using a tool like valgrind or Purify, then build the HDF5 distribution as follows to avoid getting false memory leaks reported:

HDF5-1.8

There are two configure options that were added so that false memory leaks do not occur when building HDF5:

--enable-using-memchecker turns off the internal free lists

--enable-clear-file-buffers forces memory to be initialized.

Both of these are displayed in the "configure --help" output, if you want to refer to their descriptions there.

HDF5-1.6

Set the "H5_USING_PURIFY" preprocessor symbol to force memory to be initialized and to disable the internal free lists. If you just want to disable the internal free lists, you can define "H5_NO_FREE_LISTS". These symbols should be defined when building the HDF5 distribution, and then use something like this command to configure the library, which puts the preprocessor symbols in the compile line for the library:

env CFLAGS="-DH5_USING_PURIFY" path/to/configure