diff options
author | Mohamad Chaarawi <chaarawi@hdfgroup.org> | 2012-05-18 14:18:09 (GMT) |
---|---|---|
committer | Mohamad Chaarawi <chaarawi@hdfgroup.org> | 2012-05-18 14:18:09 (GMT) |
commit | ca8d4218d2a7b888e04bd40c22cc090fb7cd207d (patch) | |
tree | 8e6745ee54ca040f8d14ffa530a5078e41d64037 | |
parent | c11b378c891d0f1209ad5af499ecd94466868528 (diff) | |
download | hdf5-ca8d4218d2a7b888e04bd40c22cc090fb7cd207d.zip hdf5-ca8d4218d2a7b888e04bd40c22cc090fb7cd207d.tar.gz hdf5-ca8d4218d2a7b888e04bd40c22cc090fb7cd207d.tar.bz2 |
[svn-r22376] add a test to expose a memory leak when adding/removing the same property in property list multiple times.
fix that bug.
-rw-r--r-- | release_docs/RELEASE.txt | 3 | ||||
-rw-r--r-- | src/H5Pint.c | 6 | ||||
-rw-r--r-- | test/tgenprop.c | 42 |
3 files changed, 49 insertions, 2 deletions
diff --git a/release_docs/RELEASE.txt b/release_docs/RELEASE.txt index 33f74c8..419bb58 100644 --- a/release_docs/RELEASE.txt +++ b/release_docs/RELEASE.txt @@ -100,7 +100,8 @@ Bug Fixes since HDF5-1.8.9 Library ------- - - None + - Fix a memory leak exposed when inserting/removing a property + from a property list several times. HDFFV-8022. (MSC 2012/05/18) Parallel Library ---------------- diff --git a/src/H5Pint.c b/src/H5Pint.c index 46a06a0..b216ab3 100644 --- a/src/H5Pint.c +++ b/src/H5Pint.c @@ -2314,9 +2314,13 @@ H5P_insert(H5P_genplist_t *plist, const char *name, size_t size, /* Check if the property has been deleted */ if(NULL != H5SL_search(plist->del, name)) { + char *temp_name = NULL; /* Remove the property name from the deleted property skip list */ - if(NULL == H5SL_remove(plist->del, name)) + if(NULL == (temp_name = H5SL_remove(plist->del, name))) HGOTO_ERROR(H5E_PLIST,H5E_CANTDELETE,FAIL,"can't remove property from deleted skip list") + + /* free the name of the removed property */ + H5MM_xfree(temp_name); } /* end if */ else { H5P_genclass_t *tclass; /* Temporary class pointer */ diff --git a/test/tgenprop.c b/test/tgenprop.c index 5f9a69b..3dbaa14 100644 --- a/test/tgenprop.c +++ b/test/tgenprop.c @@ -1575,6 +1575,46 @@ test_genprop_class_addprop(void) /**************************************************************** ** +** test_genprop_list_add_remove_prop(): Test adding then removing the +** same properties to a standard HDF5 property list. This is testing +** also for a memory leak that could be caused by not freeing the +** removed property resources from the property list. +** +****************************************************************/ +static void +test_genprop_list_add_remove_prop(void) +{ + hid_t pid; /* Property List ID */ + herr_t ret; /* Generic return value */ + + /* Create a dataset creation property list */ + pid = H5Pcreate(H5P_DATASET_CREATE); + CHECK(pid, FAIL, "H5Pcreate"); + + /* Insert temporary property into class (with no callbacks) */ + ret = H5Pinsert2(pid, PROP1_NAME, PROP1_SIZE, PROP1_DEF_VALUE, NULL, NULL, NULL, NULL, NULL, NULL); + CHECK_I(ret, "H5Pinsert2"); + + /* Delete added property */ + ret = H5Premove(pid, PROP1_NAME); + CHECK_I(ret, "H5Premove"); + + /* Insert temporary property into class (with no callbacks) */ + ret = H5Pinsert2(pid, PROP1_NAME, PROP1_SIZE, PROP1_DEF_VALUE, NULL, NULL, NULL, NULL, NULL, NULL); + CHECK_I(ret, "H5Pinsert2"); + + /* Delete added property */ + ret = H5Premove(pid, PROP1_NAME); + CHECK_I(ret, "H5Premove"); + + /* Close property list */ + ret = H5Pclose(pid); + CHECK(ret, FAIL, "H5Pclose"); + +} /* end test_genprop_list_add_remove_prop() */ + +/**************************************************************** +** ** test_genprop_equal(): Test basic generic property list code. ** More tests for H5Pequal() ** @@ -1990,6 +2030,8 @@ test_genprop(void) test_genprop_list_addprop(); /* Test adding properties to HDF5 property list */ test_genprop_class_addprop(); /* Test adding properties to HDF5 property class */ + test_genprop_list_add_remove_prop(); /* Test adding and removing the same property several times to HDF5 property list */ + test_genprop_equal(); /* Tests for more H5Pequal verification */ test_genprop_path(); /* Tests for class path verification */ test_genprop_refcount(); /* Tests for class reference counting */ |