diff options
author | Mike McGreevy <mamcgree@hdfgroup.org> | 2010-05-14 18:45:07 (GMT) |
---|---|---|
committer | Mike McGreevy <mamcgree@hdfgroup.org> | 2010-05-14 18:45:07 (GMT) |
commit | 453a3910ab7942daa7b01e821e15853cb7a0ba23 (patch) | |
tree | 04ef561bcd6f37bd07c1fea794cdbcfdc92bcd15 /src/H5Dfill.c | |
parent | fbb8709e40c97724dbb6ab137b9fb480a59e4fa5 (diff) | |
download | hdf5-453a3910ab7942daa7b01e821e15853cb7a0ba23.zip hdf5-453a3910ab7942daa7b01e821e15853cb7a0ba23.tar.gz hdf5-453a3910ab7942daa7b01e821e15853cb7a0ba23.tar.bz2 |
[svn-r18805] Purpose:
Fix memory leaks
Description
Added a routine to free memory which addresses a memory leak
when variable length strings are used as fill values.
Also added some minor tweaks to the H5I 'save ID structures' mechanic.
Tested:
h5committest and valgrind (on jam/amani) to confirm freed memory.
Diffstat (limited to 'src/H5Dfill.c')
-rw-r--r-- | src/H5Dfill.c | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/src/H5Dfill.c b/src/H5Dfill.c index f418a81..1db2976 100644 --- a/src/H5Dfill.c +++ b/src/H5Dfill.c @@ -570,6 +570,7 @@ herr_t H5D_fill_refill_vl(H5D_fill_buf_info_t *fb_info, size_t nelmts, hid_t dxpl_id) { herr_t ret_value = SUCCEED; /* Return value */ + void * buf = NULL; /* Temporary fill buffer */ FUNC_ENTER_NOAPI(H5D_fill_refill_vl, FAIL) @@ -605,11 +606,32 @@ H5D_fill_refill_vl(H5D_fill_buf_info_t *fb_info, size_t nelmts, hid_t dxpl_id) if(H5T_path_bkg(fb_info->mem_to_dset_tpath)) HDmemset(fb_info->bkg_buf, 0, fb_info->bkg_buf_size); + /* Make a copy of the fill buffer so we can free dynamic elements after conversion */ + if(fb_info->fill_alloc_func) + buf = fb_info->fill_alloc_func(fb_info->fill_buf_size, fb_info->fill_alloc_info); + else + buf = H5FL_BLK_MALLOC(non_zero_fill, fb_info->fill_buf_size); + HDmemcpy(buf, fb_info->fill_buf, fb_info->fill_buf_size); + /* Type convert the dataset buffer, to copy any VL components */ if(H5T_convert(fb_info->mem_to_dset_tpath, fb_info->mem_tid, fb_info->file_tid, nelmts, (size_t)0, (size_t)0, fb_info->fill_buf, fb_info->bkg_buf, dxpl_id) < 0) HGOTO_ERROR(H5E_DATASET, H5E_CANTCONVERT, FAIL, "data type conversion failed") done: + if (buf) { + /* Free dynamically allocated VL elements in fill buffer */ + if (fb_info->fill->type) + H5T_vlen_reclaim_elmt(buf, fb_info->fill->type, dxpl_id); + else + H5T_vlen_reclaim_elmt(buf, fb_info->mem_type, dxpl_id); + + /* Free temporary fill buffer */ + if(fb_info->fill_free_func) + fb_info->fill_free_func(buf, fb_info->fill_free_info); + else + buf = H5FL_BLK_FREE(non_zero_fill, buf); + } /* end if */ + FUNC_LEAVE_NOAPI(ret_value) } /* end H5D_fill_refill_vl() */ |