diff options
author | Mike McGreevy <mamcgree@hdfgroup.org> | 2010-05-14 18:44:36 (GMT) |
---|---|---|
committer | Mike McGreevy <mamcgree@hdfgroup.org> | 2010-05-14 18:44:36 (GMT) |
commit | ed4885a4852259db08b923eb12cec42cb24cd5c2 (patch) | |
tree | 0ed00416dfacee1323445e412559a17dfd277ad8 /src/H5Dfill.c | |
parent | 3cd3de7612a9758b6a89f09ad48da2c70c62f76a (diff) | |
download | hdf5-ed4885a4852259db08b923eb12cec42cb24cd5c2.zip hdf5-ed4885a4852259db08b923eb12cec42cb24cd5c2.tar.gz hdf5-ed4885a4852259db08b923eb12cec42cb24cd5c2.tar.bz2 |
[svn-r18804] 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.
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() */ |