From fed2ef094f85b3063b9fc9e6d9c8462e60a9ad3a Mon Sep 17 00:00:00 2001 From: Pedro Vicente Nunes Date: Fri, 25 Mar 2005 10:07:06 -0500 Subject: [svn-r10416] Purpose: bug fix Description: when exiting due to a error condition on the goto out instruction there was an attempt to call H5Dvlen_reclaim without checking if buf was null Solution: checket it Platforms tested: linux solaris IRIX64 AIX Misc. update: --- hl/src/H5DS.c | 57 +++---- hl/test/test_ds.c | 468 ++++++++++++++++++++++++++++-------------------------- 2 files changed, 271 insertions(+), 254 deletions(-) diff --git a/hl/src/H5DS.c b/hl/src/H5DS.c index 891bff3..fbff253 100644 --- a/hl/src/H5DS.c +++ b/hl/src/H5DS.c @@ -179,7 +179,7 @@ herr_t H5DSattach_scale(hid_t did, /* get dataset space */ if ((sid = H5Dget_space(did))<0) - goto out; + return FAIL; /* get rank */ if ((rank=H5Sget_simple_extent_ndims(sid))<0) @@ -187,11 +187,11 @@ herr_t H5DSattach_scale(hid_t did, /* close dataset space */ if (H5Sclose(sid)<0) - goto out; + return FAIL; /* parameter range checking */ if (idx>(unsigned)rank-1) - goto out; + return FAIL; /*------------------------------------------------------------------------- * two references are created: one to the DS, saved in "DIMENSION_LIST" @@ -200,11 +200,11 @@ herr_t H5DSattach_scale(hid_t did, */ /* create a reference for the >>DS<< dataset */ if (H5Rcreate(&ref_to_ds,dsid,".",H5R_OBJECT,-1)<0) - goto out; + return FAIL; /* create a reference for the >>data<< dataset */ if (H5Rcreate(&dsl.ref,did,".",H5R_OBJECT,-1)<0) - goto out; + return FAIL; /* try to find the attribute "DIMENSION_LIST" on the >>data<< dataset */ if ((has_dimlist = H5LT_find_attribute(did,DIMENSION_LIST))<0) @@ -220,13 +220,13 @@ herr_t H5DSattach_scale(hid_t did, dims = (hsize_t*) malloc (1 * sizeof (hsize_t)); if (dims == NULL) - goto out; + return FAIL; dims[0] = rank; /* space for the attribute */ if ((sid = H5Screate_simple(1,dims,NULL))<0) - goto out; + return FAIL; /* create the type for the attribute "DIMENSION_LIST" */ if ((tid = H5Tvlen_create(H5T_STD_REF_OBJ))<0) @@ -617,14 +617,14 @@ herr_t H5DSdetach_scale(hid_t did, */ /* try to find the attribute "DIMENSION_LIST" on the >>data<< dataset */ if ((has_dimlist = H5LT_find_attribute(did,DIMENSION_LIST))<0) - goto out; + return FAIL; if (has_dimlist == 0) - goto out; + return FAIL; /* get dataset space */ if ((sid = H5Dget_space(did))<0) - goto out; + return FAIL; /* get rank */ if ((rank=H5Sget_simple_extent_ndims(sid))<0) @@ -632,7 +632,7 @@ herr_t H5DSdetach_scale(hid_t did, /* close dataset space */ if (H5Sclose(sid)<0) - goto out; + return FAIL; /*------------------------------------------------------------------------- @@ -642,10 +642,10 @@ herr_t H5DSdetach_scale(hid_t did, /* try to find the attribute "REFERENCE_LIST" on the >>DS<< dataset */ if ((has_reflist = H5LT_find_attribute(dsid,REFERENCE_LIST))<0) - goto out; + return FAIL; if (has_reflist == 0) - goto out; + return FAIL; /*------------------------------------------------------------------------- * open "DIMENSION_LIST", and delete the reference @@ -653,7 +653,7 @@ herr_t H5DSdetach_scale(hid_t did, */ if ((aid = H5Aopen_name(did,DIMENSION_LIST))<0) - goto out; + return FAIL; if ((tid = H5Aget_type(aid))<0) goto out; @@ -927,7 +927,7 @@ int H5DSget_num_scales(hid_t did, int rank; /* rank of dataset */ hvl_t *buf; /* VL buffer to store in the attribute */ H5I_type_t it; /* ID type */ - int nscales; + int nscales; /*------------------------------------------------------------------------- * parameter checking @@ -946,7 +946,7 @@ int H5DSget_num_scales(hid_t did, */ /* get dataset space */ if ((sid = H5Dget_space(did))<0) - goto out; + return FAIL; /* get rank */ if ((rank=H5Sget_simple_extent_ndims(sid))<0) @@ -958,7 +958,7 @@ int H5DSget_num_scales(hid_t did, /* DIM range checking */ if (dim>=(unsigned int )rank) - goto out; + return FAIL; /* try to find the attribute "DIMENSION_LIST" on the >>data<< dataset */ if ((has_dimlist = H5LT_find_attribute(did,DIMENSION_LIST))<0) @@ -966,7 +966,7 @@ int H5DSget_num_scales(hid_t did, /* it does not exist */ if (has_dimlist == 0) - goto out; + return FAIL; /*------------------------------------------------------------------------- * the attribute exists, open it @@ -1075,7 +1075,7 @@ herr_t H5DSset_label(hid_t did, /* get dataset space */ if ((sid = H5Dget_space(did))<0) - goto out; + return FAIL; /* get rank */ if ((rank=H5Sget_simple_extent_ndims(sid))<0) @@ -1252,7 +1252,7 @@ ssize_t H5DSget_label(hid_t did, /* get dataset space */ if ((sid = H5Dget_space(did))<0) - goto out; + return FAIL; /* get rank */ if ((rank=H5Sget_simple_extent_ndims(sid))<0) @@ -1491,7 +1491,6 @@ htri_t H5DSis_scale(hid_t did) if (H5I_DATASET!=it) return FAIL; - /* try to find the attribute "CLASS" on the dataset */ if ((has_class = H5LT_find_attribute(did,"CLASS"))<0) return FAIL; @@ -1611,11 +1610,11 @@ herr_t H5DSiterate_scales(hid_t did, /* get the number of scales assotiated with this DIM */ if ((nscales = H5DSget_num_scales(did,dim))<0) - goto out; + return FAIL; /* get dataset space */ if ((sid = H5Dget_space(did))<0) - goto out; + return FAIL; /* get rank */ if ((rank=H5Sget_simple_extent_ndims(sid))<0) @@ -1627,7 +1626,7 @@ herr_t H5DSiterate_scales(hid_t did, /* try to find the attribute "DIMENSION_LIST" on the >>data<< dataset */ if ((has_dimlist = H5LT_find_attribute(did,DIMENSION_LIST))<0) - goto out; + return FAIL; if (has_dimlist == 0) return SUCCESS; @@ -1711,13 +1710,15 @@ herr_t H5DSiterate_scales(hid_t did, out: H5E_BEGIN_TRY { - H5Dvlen_reclaim(tid,sid,H5P_DEFAULT,buf); + if (buf) + { + H5Dvlen_reclaim(tid,sid,H5P_DEFAULT,buf); + free(buf); + } H5Sclose(sid); H5Aclose(aid); H5Tclose(tid); } H5E_END_TRY; - if (buf) - free(buf); return FAIL; } @@ -1801,7 +1802,7 @@ htri_t H5DSis_attached(hid_t did, /* get dataset space */ if ((sid = H5Dget_space(did))<0) - goto out; + return FAIL; /* get rank */ if ((rank=H5Sget_simple_extent_ndims(sid))<0) diff --git a/hl/test/test_ds.c b/hl/test/test_ds.c index e6da329..b819186 100644 --- a/hl/test/test_ds.c +++ b/hl/test/test_ds.c @@ -841,7 +841,6 @@ static int test_simple(void) if (H5Dclose(did)<0) goto out; - /*------------------------------------------------------------------------- * create 10 datasets: 5 "data" dataset and 5 dimension scales *------------------------------------------------------------------------- @@ -954,6 +953,53 @@ static int test_simple(void) PASSED(); +/*------------------------------------------------------------------------- + * create a dataset and attach only to 1 dimension + *------------------------------------------------------------------------- + */ + + TESTING2("attach only to 1 dimension"); + + /* make a dataset */ + if (H5LTmake_dataset_int(fid,"dset_e",rank,dims,NULL)<0) + goto out; + + /* make a scale */ + if (H5LTmake_dataset_int(fid,"ds_e_1",rankds,s1_dim,NULL)<0) + goto out; + + /* attach the DS to dimension 1 */ + if ((did = H5Dopen(fid,"dset_e"))<0) + goto out; + if ((dsid = H5Dopen(fid,"ds_e_1"))<0) + goto out; + if (H5DSattach_scale(did,dsid,DIM1)<0) + goto out; + if (H5DSis_attached(did,dsid,DIM1)<=0) + goto out; + + + /* try to detach all dimensions. for dimensions 0 and 2, it is an error */ + for (i=0; i