diff options
author | Jonathan Kim <jkm@hdfgroup.org> | 2011-03-22 14:26:12 (GMT) |
---|---|---|
committer | Jonathan Kim <jkm@hdfgroup.org> | 2011-03-22 14:26:12 (GMT) |
commit | 58ca19929fd614eddee99f0cdc95551d451b4a6a (patch) | |
tree | e76e89e4f363867f12b0002c0ceb8b659138a909 /tools/lib/h5tools.c | |
parent | 4674cfe1302c2ed84081c229204e923cc16ac9f8 (diff) | |
download | hdf5-58ca19929fd614eddee99f0cdc95551d451b4a6a.zip hdf5-58ca19929fd614eddee99f0cdc95551d451b4a6a.tar.gz hdf5-58ca19929fd614eddee99f0cdc95551d451b4a6a.tar.bz2 |
[svn-r20288] Purpose:
Fixed Bug 2216 - GMQS: h5diff - memory leak when compares vlen string in
dataset or attributes
Description:
Merged from HDF5 trunk r20266, r20270 and r20285.
Test for dataset : valgrind --leak-check=full ./h5diff -v h5diff_dset1.h5 h5diff_dset2.h5 /g1/VLstring
Test for attr : valgrind --leak-check=full ./h5diff h5diff_attr1.h5 h5diff_attr2.h5
Both test cases are in testing script.
Tested:
jam (linux32-LE), amani (linux64-LE), heiwa (linuxppc64-BE), Cmake - jam
Diffstat (limited to 'tools/lib/h5tools.c')
-rw-r--r-- | tools/lib/h5tools.c | 98 |
1 files changed, 82 insertions, 16 deletions
diff --git a/tools/lib/h5tools.c b/tools/lib/h5tools.c index 9790865..18d9035 100644 --- a/tools/lib/h5tools.c +++ b/tools/lib/h5tools.c @@ -627,11 +627,54 @@ h5tools_ncols(const char *s) } /*------------------------------------------------------------------------- + * Function: h5tools_detect_vlen + * + * Purpose: Recursive check for any variable length data in given type. + * + * Return: + * TRUE : type conatains any variable length data + * FALSE : type doesn't contain any variable length data + * Negative value: error occur + * + * Programmer: Jonathan Kim March 18, 2011 + *------------------------------------------------------------------------- + */ +htri_t +h5tools_detect_vlen(hid_t tid) +{ + htri_t status; + htri_t ret = FALSE; + /* recursive detect any vlen data values in type (compound, array ...) */ + status = H5Tdetect_class(tid, H5T_VLEN); + if ( (status == TRUE) || (status < 0) ) + { + ret = status; + goto done; + } + + /* recursive detect any vlen string in type (compound, array ...) */ + status = h5tools_detect_vlen_str(tid); + if ( (status == TRUE) || (status < 0) ) + + { + ret = status; + goto done; + } + +done: + return ret; +} + + +/*------------------------------------------------------------------------- * Function: h5tools_detect_vlen_str * * Purpose: Recursive check for variable length string of a datatype. * - * Return: TRUE if type conatains a variable string type, else FALSE + * Return: + * TRUE : type conatains any variable length string + * FALSE : type doesn't contain any variable length string + * Negative value: error occur * *------------------------------------------------------------------------- */ @@ -640,32 +683,55 @@ h5tools_detect_vlen_str(hid_t tid) { int i = 0; int n = 0; - htri_t has_vlen_str = FALSE; + htri_t ret = FALSE; H5T_class_t tclass = -1; + hid_t btid; + hid_t mtid; - if (H5Tis_variable_str(tid) == TRUE) - return TRUE; + ret = H5Tis_variable_str(tid); + if ( (ret == TRUE) || (ret < 0) ) + goto done; tclass = H5Tget_class(tid); - if (tclass == H5T_ARRAY) { - hid_t btid = H5Tget_super(tid); - has_vlen_str = h5tools_detect_vlen_str(btid); - H5Tclose(btid); - return has_vlen_str; + if (tclass == H5T_ARRAY) + { + btid = H5Tget_super(tid); + if (btid < 0) + { + ret = (htri_t) btid; + goto done; + } + ret = h5tools_detect_vlen_str(btid); + if ( (ret == TRUE) || (ret < 0) ) + { + H5Tclose(btid); + goto done; + } } - else if (tclass == H5T_COMPOUND) { + else if (tclass == H5T_COMPOUND) + { n = H5Tget_nmembers(tid); - for (i = 0; i < n; i++) { - hid_t mtid = H5Tget_member_type(tid, i); - has_vlen_str = h5tools_detect_vlen_str(mtid); - if (has_vlen_str == TRUE) { + if (n < 0) + { + n = ret; + goto done; + } + + for (i = 0; i < n; i++) + { + mtid = H5Tget_member_type(tid, i); + ret = h5tools_detect_vlen_str(mtid); + if ( (ret == TRUE) || (ret < 0) ) + { H5Tclose(mtid); - return TRUE; + goto done; } H5Tclose(mtid); } } - return FALSE; + +done: + return ret; } /*------------------------------------------------------------------------- |