hdf images hdf images

Valgrind Error with HDF5 1.6.6:

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.


The HDF5 library has internal free lists of memory structures, which can confuse memory allocation checking tools, like valgrind and Purify. Also, in the 1.6.x branch we were writing out "known empty, but unitialized" portions of memory, which memory checkers also whine about.

If you are going to use a tool like valgrind or Purify, here's how to build the HDF5 distribution so that you don't get false memory leaks reported. For the 1.6.x branch, 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 I usually 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

For the 1.8.0 branch, it's easier, there are two configure options that we added: --enable-using-memchecker turns off the internal free lists and --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.

- - Last modified: 13 February 2014