There seem to be a memory leak in HDF5 1.8.11 in conjunction to the H5TS_errstk_key_g thread-local variable [allocated in H5E_get_stack function in H5E.c]. The leak is only approx. 1kB large, but it still leads to "noise" in memory leak dumps that can easily hide bigger leaks. Therefore, it would be great if the leaks could be fixed for the next release.
Minimal code to reproduce:
···
---------------------------------------------
#include <hdf5.h>
#include <crtdbg.h> // for _CrtSetDbgFlag
/** Program to reproduce HDF5 memory leak. */
int main (int argc, char* argv[]) {
#ifdef _WIN32
// activate dumping of memory leaks upon program termination
// http://msdn.microsoft.com/en-us/library/e5ewb1h3.aspx
_CrtSetDbgFlag ( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF );
#endif
// create dummy HDF5 file
hid_t fid = H5Fcreate("delme.h5", H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
herr_t err = H5Fclose(fid);
if (err < 0)
return -1;
return 0;
}
---------------------------------------------
Upon termination, the following is returned:
Detected memory leaks!
Dumping objects ->
{1880} normal block at 0x005B92B0, 928 bytes long.
Data: < > 00 00 00 00 CD CD CD CD CD CD CD CD CD CD CD CD
{1879} normal block at 0x005B9268, 8 bytes long.
Data: <x ^^ > 78 F4 5E 5E 00 00 00 00
Object dump complete.
Stack trace for 1st leaked allocation:
msvcr100d.dll!malloc(unsigned int nSize=8) Line 56 + 0x15 bytes C++
hdf5_D.dll!H5FL_reg_init(H5FL_reg_head_t * head=0x583ef478) Line 239 + 0xa bytes C
hdf5_D.dll!H5FL_reg_malloc(H5FL_reg_head_t * head=0x583ef478) Line 380 + 0x9 bytes C
hdf5_D.dll!H5E_get_stack() Line 370 + 0xa bytes C
hdf5_D.dll!H5E_clear_stack(H5E_t * estack=0x00000000) Line 952 + 0x5 bytes C
hdf5_D.dll!H5Fcreate(const char * filename=0x0041573c, unsigned int flags=2, int fcpl_id=0, int fapl_id=0) Line 1458 + 0x109 bytes C
hdfleak.exe!main(int argc=1, char * * argv=0x00613b28) Line 20 + 0x2b bytes C++
Stack trace for 2nd leaked allocation:
msvcr100d.dll!malloc(unsigned int nSize=928) Line 56 + 0x15 bytes C++
hdf5_D.dll!H5FL_malloc(unsigned int mem_size=928) Line 199 + 0xc bytes C
hdf5_D.dll!H5FL_reg_malloc(H5FL_reg_head_t * head=0x583ef478) Line 399 + 0xc bytes C
hdf5_D.dll!H5E_get_stack() Line 370 + 0xa bytes C
hdf5_D.dll!H5E_clear_stack(H5E_t * estack=0x00000000) Line 952 + 0x5 bytes C
hdf5_D.dll!H5Fcreate(const char * filename=0x0041573c, unsigned int flags=2, int fcpl_id=0, int fapl_id=0) Line 1458 + 0x109 bytes C
hdfleak.exe!main(int argc=1, char * * argv=0x00613b28) Line 20 + 0x2b bytes C++
Configuration:
* Windows 7 SP1 (x64)
* Visual Studio 2010 SP1
* HDF5 1.8.11 C library compiled as 32bit DLL
Thanks in advance,
Fredrik Orderud