summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorQuincey Koziol <koziol@hdfgroup.org>2011-02-08 04:01:08 (GMT)
committerQuincey Koziol <koziol@hdfgroup.org>2011-02-08 04:01:08 (GMT)
commit20b58606caaff62d70a7bdfc03dcead16e1e30d4 (patch)
treeee342f772ca87f28b4041b6eb48eb6c8258b66e2
parent832a3db9a3a2c0d033d3c299948cbe51a816abe5 (diff)
downloadhdf5-20b58606caaff62d70a7bdfc03dcead16e1e30d4.zip
hdf5-20b58606caaff62d70a7bdfc03dcead16e1e30d4.tar.gz
hdf5-20b58606caaff62d70a7bdfc03dcead16e1e30d4.tar.bz2
[svn-r20062] Description:
Bring r20061 from trunk to 1.8 branch: Bring changes from Coverity branch to trunk: r19930: Fix memory leaks involving VL attributes in h5repack and h5diff. The buffers in copy_attr and diff_attr were not checked for the presence of a vlen before being freed, and vlen storage was never reclaimed. Added checks and calls to H5D_vlen_reclaim(). r19933: Purpose: Fix memory leak in H5L_move_cb() Description: H5L_move_cb copied the source link using H5O_msg_copy() but freed it manually using H5MM_xfree(). Since H5O_link_copy allocates the link using H5FL_MALLOC, this causes the link to be allocated from the free list but is never put back on the free list when it is freed. This prevents the link free list from shutting down properly. Modified H5L_move_cb() and H5L_move_dest_cb() to free the link properly using H5O_msg_free(). r19973: Fix resource leaks by freeing string created by HD5f2string r19974: Issue #345: Inialize buf variable to null Tested on: Mac OS X/32 10.6.6 (amazon) w/debug & production (h5committested on Coverity branch)
-rw-r--r--fortran/src/H5Ff.c33
-rw-r--r--fortran/src/H5Lf.c13
-rw-r--r--hl/src/H5DS.c266
-rw-r--r--src/H5Groot.c2
-rw-r--r--src/H5L.c23
-rw-r--r--test/bittests.c39
-rw-r--r--tools/h5repack/h5repack.c92
-rw-r--r--tools/lib/h5diff_attr.c216
8 files changed, 290 insertions, 394 deletions
diff --git a/fortran/src/H5Ff.c b/fortran/src/H5Ff.c
index 1570bb3..3cfc9e3 100644
--- a/fortran/src/H5Ff.c
+++ b/fortran/src/H5Ff.c
@@ -47,37 +47,36 @@ nh5fcreate_c(_fcd name, int_f *namelen, int_f *access_flags, hid_t_f* crt_prp, h
* Define access flags
*/
c_access_flags = (unsigned) *access_flags;
+
/*
* Define creation property
*/
c_crt_prp = *crt_prp;
-/*
- if ( H5P_DEFAULT_F == c_crt_prp ) c_crt_prp = H5P_DEFAULT;
-*/
+
/*
* Define access property
*/
c_acc_prp = *acc_prp;
-/*
- if ( H5P_DEFAULT_F == c_acc_prp ) c_acc_prp = H5P_DEFAULT;
-*/
/*
* Convert FORTRAN name to C name
*/
c_namelen = *namelen;
c_name = (char *)HD5f2cstring(name, (size_t)c_namelen);
- if (c_name == NULL) return ret_value;
+ if(c_name == NULL)
+ return ret_value;
/*
* Call H5Fcreate function.
*/
c_file_id = H5Fcreate(c_name, c_access_flags, c_crt_prp, c_acc_prp);
- if (c_file_id < 0) return ret_value;
- *file_id = c_file_id;
+ if (c_file_id >= 0) {
+ ret_value = 0;
+ *file_id = c_file_id;
+ }
+
HDfree(c_name);
- ret_value = 0;
return ret_value;
}
@@ -238,31 +237,31 @@ nh5fopen_c (_fcd name, int_f *namelen, int_f *access_flags, hid_t_f *acc_prp, hi
* Define access flags
*/
c_access_flags = (unsigned) *access_flags;
+
/*
* Define access property
*/
c_acc_prp = *acc_prp;
-/*
- if ( H5P_DEFAULT_F == c_acc_prp ) c_acc_prp = H5P_DEFAULT;
-*/
/*
* Convert FORTRAN name to C name
*/
c_namelen = *namelen;
c_name = (char *)HD5f2cstring(name, (size_t)c_namelen);
- if (c_name == NULL) return ret_value;
+ if(c_name == NULL)
+ return ret_value;
/*
* Call H5Fopen function.
*/
c_file_id = H5Fopen(c_name, c_access_flags, c_acc_prp);
- if (c_file_id < 0) return ret_value;
- *file_id = (hid_t_f)c_file_id;
+ if(c_file_id >= 0) {
+ ret_value = 0;
+ *file_id = (hid_t_f)c_file_id;
+ } /* end if */
HDfree(c_name);
- ret_value = 0;
return ret_value;
}
diff --git a/fortran/src/H5Lf.c b/fortran/src/H5Lf.c
index 59f4535..c971d5e 100644
--- a/fortran/src/H5Lf.c
+++ b/fortran/src/H5Lf.c
@@ -394,7 +394,7 @@ done:
* Modifications: N/A
*---------------------------------------------------------------------------*/
int_f
-nh5lget_info_c (hid_t_f *link_loc_id, _fcd link_name, size_t_f *link_namelen,
+nh5lget_info_c(hid_t_f *link_loc_id, _fcd link_name, size_t_f *link_namelen,
int_f *cset, int_f *corder, int_f *corder_valid, int_f *link_type,
haddr_t_f *address, size_t_f *val_size,
hid_t_f *lapl_id)
@@ -406,16 +406,16 @@ nh5lget_info_c (hid_t_f *link_loc_id, _fcd link_name, size_t_f *link_namelen,
/*
* Convert FORTRAN name to C name
*/
- if((c_link_name = HD5f2cstring(link_name, (size_t)*link_namelen)) == NULL)
- HGOTO_DONE(FAIL);
+ if(NULL == (c_link_name = HD5f2cstring(link_name, (size_t)*link_namelen)))
+ HGOTO_DONE(FAIL);
+
/*
* Call H5Linfo function.
*/
if(H5Lget_info((hid_t)*link_loc_id, c_link_name, &link_buff, (hid_t)*lapl_id) < 0)
- HGOTO_DONE(FAIL);
+ HGOTO_DONE(FAIL);
/* Unpack the structure */
-
*cset = (int_f)link_buff.cset;
*corder = (int_f)link_buff.corder;
*corder_valid = 0;
@@ -425,6 +425,9 @@ nh5lget_info_c (hid_t_f *link_loc_id, _fcd link_name, size_t_f *link_namelen,
*val_size = (size_t_f)link_buff.u.val_size;
done:
+ if(c_link_name)
+ HDfree(c_link_name);
+
return ret_value;
}
diff --git a/hl/src/H5DS.c b/hl/src/H5DS.c
index faa6d30..432a725 100644
--- a/hl/src/H5DS.c
+++ b/hl/src/H5DS.c
@@ -132,12 +132,12 @@ herr_t H5DSattach_scale(hid_t did,
hid_t ntid = -1; /* attribute native type ID */
hid_t aid = -1; /* attribute ID */
int rank; /* rank of dataset */
- hsize_t dims[1]; /* dimension of the "REFERENCE_LIST" array */
+ hsize_t dims[1]; /* dimension of the "REFERENCE_LIST" array */
ds_list_t dsl; /* attribute data in the DS pointing to the dataset */
- ds_list_t *dsbuf=NULL; /* array of attribute data in the DS pointing to the dataset */
+ ds_list_t *dsbuf = NULL; /* array of attribute data in the DS pointing to the dataset */
hobj_ref_t ref_to_ds; /* reference to the DS */
hobj_ref_t ref_j; /* iterator reference */
- hvl_t *buf=NULL; /* VL buffer to store in the attribute */
+ hvl_t *buf = NULL; /* VL buffer to store in the attribute */
hid_t dsid_j; /* DS dataset ID in DIMENSION_LIST */
H5O_info_t oi1, oi2;
H5I_type_t it1, it2;
@@ -254,8 +254,7 @@ herr_t H5DSattach_scale(hid_t did,
goto out;
/* allocate and initialize the VL */
- buf = (hvl_t*)malloc((size_t)rank * sizeof(hvl_t));
-
+ buf = (hvl_t *)malloc((size_t)rank * sizeof(hvl_t));
if(buf == NULL)
goto out;
@@ -270,25 +269,21 @@ herr_t H5DSattach_scale(hid_t did,
((hobj_ref_t *)buf[idx].p)[0] = ref_to_ds;
/* write the attribute with the reference */
- if (H5Awrite(aid,tid,buf) < 0)
+ if(H5Awrite(aid, tid, buf) < 0)
goto out;
/* close */
- if (H5Dvlen_reclaim(tid,sid,H5P_DEFAULT,buf) < 0)
+ if(H5Dvlen_reclaim(tid, sid, H5P_DEFAULT, buf) < 0)
goto out;
- if (H5Sclose(sid) < 0)
+ if(H5Sclose(sid) < 0)
goto out;
- if (H5Tclose(tid) < 0)
+ if(H5Tclose(tid) < 0)
goto out;
- if (H5Aclose(aid) < 0)
+ if(H5Aclose(aid) < 0)
goto out;
- if (buf)
- {
- free(buf);
- buf = NULL;
- }
-
+ free(buf);
+ buf = NULL;
}
/*-------------------------------------------------------------------------
@@ -296,8 +291,7 @@ herr_t H5DSattach_scale(hid_t did,
* and insert the new reference
*-------------------------------------------------------------------------
*/
-
- else if ( has_dimlist == 1 )
+ else if(has_dimlist == 1)
{
if((aid = H5Aopen(did, DIMENSION_LIST, H5P_DEFAULT)) < 0)
goto out;
@@ -309,8 +303,7 @@ herr_t H5DSattach_scale(hid_t did,
goto out;
/* allocate and initialize the VL */
- buf = (hvl_t*)malloc((size_t)rank * sizeof(hvl_t));
-
+ buf = (hvl_t *)malloc((size_t)rank * sizeof(hvl_t));
if(buf == NULL)
goto out;
@@ -320,13 +313,12 @@ herr_t H5DSattach_scale(hid_t did,
/* check to avoid inserting duplicates. it is not FAIL, just do nothing */
/* iterate all the REFs in this dimension IDX */
- for (i=0; i<(int)buf[idx].len; i++)
- {
+ for(i = 0; i < (int)buf[idx].len; i++) {
/* get the reference */
ref_j = ((hobj_ref_t *)buf[idx].p)[i];
/* get the scale id for this REF */
- if ((dsid_j = H5Rdereference(did,H5R_OBJECT,&ref_j)) < 0)
+ if((dsid_j = H5Rdereference(did,H5R_OBJECT,&ref_j)) < 0)
goto out;
/* get info for DS in the parameter list */
@@ -342,48 +334,41 @@ herr_t H5DSattach_scale(hid_t did,
found_ds = 1;
/* close the dereferenced dataset */
- if (H5Dclose(dsid_j) < 0)
+ if(H5Dclose(dsid_j) < 0)
goto out;
- }
+ } /* end for */
- if (found_ds==0)
- {
+ if(found_ds == 0) {
/* we are adding one more DS to this dimension */
- if ( buf[idx].len > 0 )
- {
+ if(buf[idx].len > 0) {
buf[idx].len++;
len = buf[idx].len;
- buf[idx].p = realloc( buf[idx].p, len * sizeof(hobj_ref_t));
- ((hobj_ref_t *)buf[idx].p)[ len-1 ] = ref_to_ds;
- }
- else
- {
+ buf[idx].p = realloc(buf[idx].p, len * sizeof(hobj_ref_t));
+ ((hobj_ref_t *)buf[idx].p)[len - 1] = ref_to_ds;
+ } /* end if */
+ else {
/* store the REF information in the index of the dataset that has the DS */
buf[idx].len = 1;
- buf[idx].p = malloc( 1 * sizeof(hobj_ref_t));
+ buf[idx].p = malloc(sizeof(hobj_ref_t));
((hobj_ref_t *)buf[idx].p)[0] = ref_to_ds;
- }
- }
+ } /* end else */
+ } /* end if */
/* write the attribute with the new references */
- if (H5Awrite(aid,tid,buf) < 0)
+ if(H5Awrite(aid, tid, buf) < 0)
goto out;
/* close */
- if (H5Dvlen_reclaim(tid,sid,H5P_DEFAULT,buf) < 0)
+ if(H5Dvlen_reclaim(tid, sid, H5P_DEFAULT, buf) < 0)
goto out;
- if (H5Sclose(sid) < 0)
+ if(H5Sclose(sid) < 0)
goto out;
- if (H5Tclose(tid) < 0)
+ if(H5Tclose(tid) < 0)
goto out;
- if (H5Aclose(aid) < 0)
+ if(H5Aclose(aid) < 0)
goto out;
- if (buf)
- {
- free(buf);
- buf = NULL;
- }
-
+ free(buf);
+ buf = NULL;
} /* has_dimlist */
/*-------------------------------------------------------------------------
@@ -392,20 +377,18 @@ herr_t H5DSattach_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)
+ if((has_reflist = H5LT_find_attribute(dsid, REFERENCE_LIST)) < 0)
goto out;
/*-------------------------------------------------------------------------
* it does not exist. we create the attribute and its reference data
*-------------------------------------------------------------------------
*/
- if (has_reflist == 0)
- {
-
+ if(has_reflist == 0) {
dims[0] = 1;
/* space for the attribute */
- if ((sid = H5Screate_simple(1,dims,NULL)) < 0)
+ if((sid = H5Screate_simple(1,dims,NULL)) < 0)
goto out;
/* create the compound datatype for the attribute "REFERENCE_LIST" */
@@ -438,16 +421,13 @@ herr_t H5DSattach_scale(hid_t did,
goto out;
if(H5Aclose(aid) < 0)
goto out;
-
- }
+ } /* end if */
/*-------------------------------------------------------------------------
* the "REFERENCE_LIST" array already exists, open it and extend it
*-------------------------------------------------------------------------
*/
-
- else if(has_reflist == 1)
- {
+ else if(has_reflist == 1) {
if((aid = H5Aopen(dsid, REFERENCE_LIST, H5P_DEFAULT)) < 0)
goto out;
@@ -468,17 +448,16 @@ herr_t H5DSattach_scale(hid_t did,
nelmts++;
dsbuf = (ds_list_t*) malloc((size_t)nelmts * sizeof(ds_list_t));
-
- if (dsbuf == NULL)
+ if(dsbuf == NULL)
goto out;
- if (H5Aread(aid,ntid,dsbuf) < 0)
+ if(H5Aread(aid, ntid, dsbuf) < 0)
goto out;
/* close */
- if (H5Sclose(sid) < 0)
+ if(H5Sclose(sid) < 0)
goto out;
- if (H5Aclose(aid) < 0)
+ if(H5Aclose(aid) < 0)
goto out;
/*-------------------------------------------------------------------------
@@ -492,7 +471,7 @@ herr_t H5DSattach_scale(hid_t did,
/* store the IDX information (index of the dataset that has the DS) */
dsl.dim_idx = idx;
- dsbuf[nelmts-1] = dsl;
+ dsbuf[nelmts - 1] = dsl;
/* create a new data space for the new references array */
dims[0] = nelmts;
@@ -518,12 +497,8 @@ herr_t H5DSattach_scale(hid_t did,
if (H5Tclose(ntid) < 0)
goto out;
- if (dsbuf)
- {
- free(dsbuf);
- dsbuf = NULL;
- }
-
+ free(dsbuf);
+ dsbuf = NULL;
} /* has_reflist */
/*-------------------------------------------------------------------------
@@ -531,11 +506,10 @@ herr_t H5DSattach_scale(hid_t did,
*-------------------------------------------------------------------------
*/
- if ((is_ds=H5DSis_scale(dsid)) < 0)
+ if((is_ds=H5DSis_scale(dsid)) < 0)
return FAIL;
- if (is_ds == 0 )
- {
+ if(is_ds == 0) {
if (H5LT_set_attribute_string(dsid,"CLASS",DIMENSION_SCALE_CLASS) < 0)
return FAIL;
}
@@ -544,17 +518,10 @@ herr_t H5DSattach_scale(hid_t did,
/* error zone */
out:
-
- if (buf)
- {
+ if(buf)
free(buf);
- buf = NULL;
- }
- if (dsbuf)
- {
+ if(dsbuf)
free(dsbuf);
- dsbuf = NULL;
- }
H5E_BEGIN_TRY {
H5Sclose(sid);
@@ -706,13 +673,12 @@ herr_t H5DSdetach_scale(hid_t did,
goto out;
/* allocate and initialize the VL */
- buf = (hvl_t*)malloc((size_t)rank * sizeof(hvl_t));
-
+ buf = (hvl_t *)malloc((size_t)rank * sizeof(hvl_t));
if(buf == NULL)
goto out;
/* read */
- if (H5Aread(aid,tid,buf) < 0)
+ if(H5Aread(aid, tid, buf) < 0)
goto out;
/* reset */
@@ -747,7 +713,8 @@ herr_t H5DSdetach_scale(hid_t did,
and reset to NULL */
size_t len = buf[idx].len;
- if(j<len-1)
+
+ if(j < len - 1)
((hobj_ref_t *)buf[idx].p)[j] = ((hobj_ref_t *)buf[idx].p)[len-1];
len = --buf[idx].len;
if(len == 0) {
@@ -768,36 +735,33 @@ herr_t H5DSdetach_scale(hid_t did,
/* Write the attribute, but check first, if we have any scales left,
because if not, we should delete the attribute according to the spec */
- for(i=0; i < rank; i++) {
+ for(i = 0; i < rank; i++) {
if(buf[i].len > 0) {
have_ds = 1;
break;
}
}
if(have_ds) {
- if(H5Awrite(aid,tid,buf) < 0)
+ if(H5Awrite(aid, tid, buf) < 0)
goto out;
}
else {
- if(H5Adelete(did,DIMENSION_LIST) < 0)
+ if(H5Adelete(did, DIMENSION_LIST) < 0)
goto out;
}
/* close */
- if (H5Dvlen_reclaim(tid,sid,H5P_DEFAULT,buf) < 0)
+ if(H5Dvlen_reclaim(tid, sid, H5P_DEFAULT, buf) < 0)
goto out;
- if (H5Sclose(sid) < 0)
+ if(H5Sclose(sid) < 0)
goto out;
- if (H5Tclose(tid) < 0)
+ if(H5Tclose(tid) < 0)
goto out;
- if (H5Aclose(aid) < 0)
+ if(H5Aclose(aid) < 0)
goto out;
- if (buf)
- {
- free(buf);
- buf = NULL;
- }
+ free(buf);
+ buf = NULL;
/*-------------------------------------------------------------------------
@@ -826,7 +790,7 @@ herr_t H5DSdetach_scale(hid_t did,
if(dsbuf == NULL)
goto out;
- if (H5Aread(aid,ntid,dsbuf) < 0)
+ if(H5Aread(aid, ntid, dsbuf) < 0)
goto out;
for(ii=0; ii<nelmts; ii++) {
@@ -914,12 +878,8 @@ herr_t H5DSdetach_scale(hid_t did,
if (H5Tclose(ntid) < 0)
goto out;
- if (dsbuf)
- {
- free(dsbuf);
- dsbuf=NULL;
- }
-
+ free(dsbuf);
+ dsbuf = NULL;
return SUCCEED;
@@ -931,21 +891,19 @@ out:
H5Tclose(ntid);
H5Tclose(tid);
- if (dsbuf)
- {
+ if(dsbuf) {
free(dsbuf);
- dsbuf=NULL;
+ dsbuf = NULL;
}
- if (buf)
- {
+ if(buf) {
/* Failure occured before H5Dvlen_reclaim was called;
free the pointers allocated when we read data in */
- for(i=0; i<rank; i++) {
+ for(i = 0; i < rank; i++) {
if(buf[i].p)
free(buf[i].p);
}
free(buf);
- buf=NULL;
+ buf = NULL;
}
} H5E_END_TRY;
return FAIL;
@@ -991,9 +949,9 @@ htri_t H5DSis_attached(hid_t did,
hid_t ntid = -1; /* attribute native type ID */
hid_t aid = -1; /* attribute ID */
int rank; /* rank of dataset */
- ds_list_t *dsbuf; /* array of attribute data in the DS pointing to the dataset */
+ ds_list_t *dsbuf = NULL; /* array of attribute data in the DS pointing to the dataset */
hobj_ref_t ref; /* reference to the DS */
- hvl_t *buf; /* VL buffer to store in the attribute */
+ hvl_t *buf = NULL; /* VL buffer to store in the attribute */
hid_t dsid_j; /* DS dataset ID in DIMENSION_LIST */
hid_t did_i; /* dataset ID in REFERENCE_LIST */
H5O_info_t oi1, oi2, oi3, oi4;
@@ -1078,7 +1036,6 @@ htri_t H5DSis_attached(hid_t did,
/* allocate and initialize the VL */
buf = (hvl_t*)malloc((size_t)rank * sizeof(hvl_t));
-
if(buf == NULL)
goto out;
@@ -1124,11 +1081,8 @@ htri_t H5DSis_attached(hid_t did,
goto out;
if (H5Aclose(aid) < 0)
goto out;
- if (buf)
- {
- free(buf);
- buf = NULL;
- }
+ free(buf);
+ buf = NULL;
} /* has_dimlist */
/*-------------------------------------------------------------------------
@@ -1217,11 +1171,9 @@ htri_t H5DSis_attached(hid_t did,
goto out;
if (H5Aclose(aid) < 0)
goto out;
- if (dsbuf)
- {
- free(dsbuf);
- dsbuf = NULL;
- }
+
+ free(dsbuf);
+ dsbuf = NULL;
} /* has_reflist */
if (found_ds && found_dset)
@@ -1238,13 +1190,11 @@ out:
H5Tclose(ntid);
} H5E_END_TRY;
- if (buf)
- {
+ if (buf) {
free(buf);
buf = NULL;
}
- if (dsbuf)
- {
+ if(dsbuf) {
free(dsbuf);
dsbuf = NULL;
}
@@ -1307,7 +1257,7 @@ herr_t H5DSiterate_scales(hid_t did,
hid_t sid; /* space ID */
hid_t tid = -1; /* attribute type ID */
hid_t aid = -1; /* attribute ID */
- hvl_t *buf=NULL; /* VL buffer to store in the attribute */
+ hvl_t *buf = NULL; /* VL buffer to store in the attribute */
H5I_type_t it; /* ID type */
herr_t ret_value=0;
int j_idx;
@@ -1431,20 +1381,16 @@ herr_t H5DSiterate_scales(hid_t did,
goto out;
if (H5Aclose(aid) < 0)
goto out;
- if (buf)
- {
- free(buf);
- buf = NULL;
- }
+ free(buf);
+ buf = NULL;
} /* if has_dimlist */
return ret_value;
out:
H5E_BEGIN_TRY {
- if (buf)
- {
+ if(buf) {
H5Dvlen_reclaim(tid,sid,H5P_DEFAULT,buf);
free(buf);
}
@@ -1452,6 +1398,7 @@ out:
H5Aclose(aid);
H5Tclose(tid);
} H5E_END_TRY;
+
return FAIL;
}
@@ -2048,7 +1995,7 @@ int H5DSget_num_scales(hid_t did,
hid_t tid = -1; /* attribute type ID */
hid_t aid = -1; /* attribute ID */
int rank; /* rank of dataset */
- hvl_t *buf; /* VL buffer to store in the attribute */
+ hvl_t *buf = NULL; /* VL buffer to store in the attribute */
H5I_type_t it; /* ID type */
int nscales;
@@ -2057,10 +2004,10 @@ int H5DSget_num_scales(hid_t did,
*-------------------------------------------------------------------------
*/
/* get ID type */
- if ((it = H5Iget_type(did)) < 0)
+ if((it = H5Iget_type(did)) < 0)
return FAIL;
- if (H5I_DATASET!=it)
+ if(H5I_DATASET != it)
return FAIL;
/*-------------------------------------------------------------------------
@@ -2068,19 +2015,19 @@ int H5DSget_num_scales(hid_t did,
*-------------------------------------------------------------------------
*/
/* get dataset space */
- if ((sid = H5Dget_space(did)) < 0)
+ if((sid = H5Dget_space(did)) < 0)
return FAIL;
/* get rank */
- if ((rank=H5Sget_simple_extent_ndims(sid)) < 0)
+ if((rank = H5Sget_simple_extent_ndims(sid)) < 0)
goto out;
/* close dataset space */
- if (H5Sclose(sid) < 0)
+ if(H5Sclose(sid) < 0)
goto out;
/* dimemsion index IDX range checking */
- if (idx>=(unsigned int )rank)
+ if(idx >= (unsigned int )rank)
return FAIL;
/* try to find the attribute "DIMENSION_LIST" on the >>data<< dataset */
@@ -2095,9 +2042,7 @@ int H5DSget_num_scales(hid_t did,
* the attribute exists, open it
*-------------------------------------------------------------------------
*/
-
- else
- {
+ else {
if((aid = H5Aopen(did, DIMENSION_LIST, H5P_DEFAULT)) < 0)
goto out;
if((tid = H5Aget_type(aid)) < 0)
@@ -2106,8 +2051,7 @@ int H5DSget_num_scales(hid_t did,
goto out;
/* allocate and initialize the VL */
- buf = (hvl_t*)malloc((size_t)rank * sizeof(hvl_t));
-
+ buf = (hvl_t *)malloc((size_t)rank * sizeof(hvl_t));
if(buf == NULL)
goto out;
@@ -2115,23 +2059,19 @@ int H5DSget_num_scales(hid_t did,
if(H5Aread(aid, tid, buf) < 0)
goto out;
- nscales=(int)buf[idx].len;
+ nscales = (int)buf[idx].len;
/* close */
- if (H5Dvlen_reclaim(tid,sid,H5P_DEFAULT,buf) < 0)
+ if(H5Dvlen_reclaim(tid, sid, H5P_DEFAULT, buf) < 0)
goto out;
- if (H5Sclose(sid) < 0)
+ if(H5Sclose(sid) < 0)
goto out;
- if (H5Tclose(tid) < 0)
+ if(H5Tclose(tid) < 0)
goto out;
- if (H5Aclose(aid) < 0)
+ if(H5Aclose(aid) < 0)
goto out;
- if (buf)
- {
- free(buf);
- buf = NULL;
- }
-
+ free(buf);
+ buf = NULL;
} /* has_dimlist */
return nscales;
@@ -2144,11 +2084,9 @@ out:
H5Tclose(tid);
} H5E_END_TRY;
- if (buf)
- {
+ if(buf)
free(buf);
- buf = NULL;
- }
+
return FAIL;
}
diff --git a/src/H5Groot.c b/src/H5Groot.c
index b8ba0fd..ff4a8c4 100644
--- a/src/H5Groot.c
+++ b/src/H5Groot.c
@@ -15,7 +15,7 @@
/*-------------------------------------------------------------------------
*
- * Created: H5Gobj.c
+ * Created: H5Groot.c
* Apr 8 2009
* Neil Fortner <nfortne2@hdfgroup.org>
*
diff --git a/src/H5L.c b/src/H5L.c
index 6448c03..0b25928 100644
--- a/src/H5L.c
+++ b/src/H5L.c
@@ -2414,8 +2414,8 @@ H5L_move_dest_cb(H5G_loc_t *grp_loc/*in*/, const char *name,
H5G_own_loc_t *own_loc/*out*/)
{
H5L_trav_mv2_t *udata = (H5L_trav_mv2_t *)_udata; /* User data passed in */
- H5G_t *grp=NULL; /* H5G_t for this group, opened to pass to user callback */
- hid_t grp_id = FAIL; /* Id for this group (passed to user callback */
+ H5G_t *grp = NULL; /* H5G_t for this group, opened to pass to user callback */
+ hid_t grp_id = FAIL; /* ID for this group (passed to user callback */
H5G_loc_t temp_loc; /* For UD callback */
hbool_t temp_loc_init = FALSE;
herr_t ret_value = SUCCEED; /* Return value */
@@ -2500,6 +2500,10 @@ done:
* location for the object */
*own_loc = H5G_OWN_NONE;
+ /* Reset the "name" field in udata->lnk because it is owned by traverse()
+ * and must not be manipulated after traverse closes */
+ udata->lnk->name = NULL;
+
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5L_move_dest_cb() */
@@ -2539,7 +2543,7 @@ H5L_move_cb(H5G_loc_t *grp_loc/*in*/, const char *name, const H5O_link_t *lnk,
HGOTO_ERROR(H5E_SYM, H5E_NOTFOUND, FAIL, "the name of a link must be supplied to move or copy")
/* Set up user data for move_dest_cb */
- if((udata_out.lnk = (H5O_link_t *)H5O_msg_copy(H5O_LINK_ID, lnk, NULL)) == NULL)
+ if(NULL == (udata_out.lnk = (H5O_link_t *)H5O_msg_copy(H5O_LINK_ID, lnk, NULL)))
HGOTO_ERROR(H5E_LINK, H5E_CANTCOPY, FAIL, "unable to copy link to be moved")
/* In this special case, the link's name is going to be replaced at its
@@ -2600,16 +2604,11 @@ done:
H5MM_xfree(orig_name);
/* If udata_out.lnk was copied, free any memory allocated
- * In this special case, the H5L_move_dest_cb callback frees the name
- * if it succeeds
+ * In this special case, the H5L_move_dest_cb callback resets the name
+ * so H5O_msg_free shouldn't try to free it
*/
- if(link_copied) {
- if(udata_out.lnk->type == H5L_TYPE_SOFT)
- udata_out.lnk->u.soft.name = (char *)H5MM_xfree(udata_out.lnk->u.soft.name);
- else if(udata_out.lnk->type >= H5L_TYPE_UD_MIN && udata_out.lnk->u.ud.size > 0)
- udata_out.lnk->u.ud.udata = H5MM_xfree(udata_out.lnk->u.ud.udata);
- H5MM_xfree(udata_out.lnk);
- } /* end if */
+ if(link_copied)
+ H5O_msg_free(H5O_LINK_ID, udata_out.lnk);
/* Indicate that this callback didn't take ownership of the group *
* location for the object */
diff --git a/test/bittests.c b/test/bittests.c
index e435d6c..f063cee 100644
--- a/test/bittests.c
+++ b/test/bittests.c
@@ -908,41 +908,36 @@ test_clear (void)
* Programmer: Robb Matzke
* Tuesday, June 16, 1998
*
- * Modifications:
- *
*-------------------------------------------------------------------------
*/
int
-main (void)
+main(void)
{
- int nerrors=0;
+ int nerrors = 0;
/*
- * Open the library explicitly for thread-safe builds, so per-thread
- * things are initialized correctly.
+ * Open the library explicitly.
*/
-#ifdef H5_HAVE_THREADSAFE
H5open();
-#endif /* H5_HAVE_THREADSAFE */
-
- nerrors += test_find ()<0?1:0;
- nerrors += test_set ()<0?1:0;
- nerrors += test_clear()<0?1:0;
- nerrors += test_copy ()<0?1:0;
- nerrors += test_shift()<0?1:0;
- nerrors += test_increment ()<0?1:0;
- nerrors += test_decrement ()<0?1:0;
- nerrors += test_negate ()<0?1:0;
-
- if (nerrors) {
+
+ nerrors += test_find() < 0 ? 1 : 0;
+ nerrors += test_set() < 0 ? 1 : 0;
+ nerrors += test_clear() < 0 ? 1 : 0;
+ nerrors += test_copy() < 0 ? 1 : 0;
+ nerrors += test_shift() < 0 ? 1 : 0;
+ nerrors += test_increment() < 0 ? 1 : 0;
+ nerrors += test_decrement() < 0 ? 1 : 0;
+ nerrors += test_negate() < 0 ? 1 : 0;
+
+ if(nerrors) {
printf("***** %u FAILURE%s! *****\n",
- nerrors, 1==nerrors?"":"S");
+ nerrors, 1 == nerrors ? "" : "S");
exit(1);
}
printf("All bit tests passed.\n");
-#ifdef H5_HAVE_THREADSAFE
H5close();
-#endif /* H5_HAVE_THREADSAFE */
+
return 0;
}
+
diff --git a/tools/h5repack/h5repack.c b/tools/h5repack/h5repack.c
index 4a1f4d7..6672b68 100644
--- a/tools/h5repack/h5repack.c
+++ b/tools/h5repack/h5repack.c
@@ -404,7 +404,7 @@ int copy_attr(hid_t loc_in,
hid_t ftype_id=-1; /* file type ID */
hid_t wtype_id=-1; /* read/write type ID */
size_t msize; /* size of type */
- void *buf=NULL; /* data buffer */
+ void *buf = NULL; /* data buffer */
hsize_t nelmts; /* number of elements in dataset */
int rank; /* rank of dataset */
htri_t is_named; /* Whether the datatype is named */
@@ -421,28 +421,23 @@ int copy_attr(hid_t loc_in,
* copy all attributes
*-------------------------------------------------------------------------
*/
-
- for ( u = 0; u < (unsigned)oinfo.num_attrs; u++)
- {
- buf=NULL;
-
+ for(u = 0; u < (unsigned)oinfo.num_attrs; u++) {
/* open attribute */
if((attr_id = H5Aopen_by_idx(loc_in, ".", H5_INDEX_CRT_ORDER, H5_ITER_INC, (hsize_t)u, H5P_DEFAULT, H5P_DEFAULT)) < 0)
goto error;
/* get name */
- if (H5Aget_name( attr_id, (size_t)255, name ) < 0)
+ if(H5Aget_name(attr_id, (size_t)255, name) < 0)
goto error;
/* get the file datatype */
- if ((ftype_id = H5Aget_type( attr_id )) < 0 )
+ if((ftype_id = H5Aget_type(attr_id)) < 0 )
goto error;
/* Check if the datatype is committed */
if((is_named = H5Tcommitted(ftype_id)) < 0)
goto error;
- if(is_named)
- {
+ if(is_named && travt) {
hid_t fidout;
/* Create out file id */
@@ -460,29 +455,26 @@ int copy_attr(hid_t loc_in,
if(H5Fclose(fidout) < 0)
goto error;
} /* end if */
+ else {
+ if(options->use_native == 1)
+ wtype_id = h5tools_get_native_type(ftype_id);
+ else
+ wtype_id = H5Tcopy(ftype_id);
+ } /* end else */
/* get the dataspace handle */
- if ((space_id = H5Aget_space( attr_id )) < 0 )
+ if((space_id = H5Aget_space(attr_id)) < 0)
goto error;
/* get dimensions */
- if ( (rank = H5Sget_simple_extent_dims(space_id, dims, NULL)) < 0 )
+ if((rank = H5Sget_simple_extent_dims(space_id, dims, NULL)) < 0)
goto error;
- nelmts=1;
- for (j=0; j<rank; j++)
- nelmts*=dims[j];
+ nelmts = 1;
+ for(j = 0; j < rank; j++)
+ nelmts *= dims[j];
- /* wtype_id will have already been set if using a named dtype */
- if(!is_named)
- {
- if (options->use_native==1)
- wtype_id = h5tools_get_native_type(ftype_id);
- else
- wtype_id = H5Tcopy(ftype_id);
- } /* end if */
-
- if ((msize=H5Tget_size(wtype_id))==0)
+ if((msize = H5Tget_size(wtype_id)) == 0)
goto error;
/*-------------------------------------------------------------------------
@@ -493,23 +485,20 @@ int copy_attr(hid_t loc_in,
*-------------------------------------------------------------------------
*/
- if (H5T_REFERENCE==H5Tget_class(wtype_id))
- {
+ if(H5T_REFERENCE == H5Tget_class(wtype_id)) {
;
}
- else
- {
+ else {
/*-------------------------------------------------------------------------
* read to memory
*-------------------------------------------------------------------------
*/
buf = (void *)HDmalloc((size_t)(nelmts * msize));
- if(buf == NULL)
- {
+ if(buf == NULL) {
error_msg("h5repack", "cannot read into memory\n" );
goto error;
- }
+ } /* end if */
if(H5Aread(attr_id, wtype_id, buf) < 0)
goto error;
@@ -527,10 +516,12 @@ int copy_attr(hid_t loc_in,
if(H5Aclose(attr_out) < 0)
goto error;
-
- if(buf)
- free(buf);
-
+ /* Check if we have VL data in the attribute's datatype that must
+ * be reclaimed */
+ if(TRUE == H5Tdetect_class(wtype_id, H5T_VLEN))
+ H5Dvlen_reclaim(wtype_id, space_id, H5P_DEFAULT, buf);
+ HDfree(buf);
+ buf = NULL;
} /*H5T_REFERENCE*/
@@ -542,28 +533,39 @@ int copy_attr(hid_t loc_in,
*-------------------------------------------------------------------------
*/
- if (H5Tclose(ftype_id) < 0) goto error;
- if (H5Tclose(wtype_id) < 0) goto error;
- if (H5Sclose(space_id) < 0) goto error;
- if (H5Aclose(attr_id) < 0) goto error;
-
+ if(H5Tclose(ftype_id) < 0)
+ goto error;
+ if(H5Tclose(wtype_id) < 0)
+ goto error;
+ if(H5Sclose(space_id) < 0)
+ goto error;
+ if(H5Aclose(attr_id) < 0)
+ goto error;
} /* u */
-
return 0;
error:
H5E_BEGIN_TRY {
+ if(buf) {
+ /* Check if we have VL data in the attribute's datatype that must
+ * be reclaimed */
+ if(TRUE == H5Tdetect_class(wtype_id, H5T_VLEN))
+ H5Dvlen_reclaim(wtype_id, space_id, H5P_DEFAULT, buf);
+
+ /* Free buf */
+ free(buf);
+ } /* end if */
+
H5Tclose(ftype_id);
H5Tclose(wtype_id);
H5Sclose(space_id);
H5Aclose(attr_id);
H5Aclose(attr_out);
- if (buf)
- free(buf);
} H5E_END_TRY;
+
return -1;
-}
+} /* end copy_attr() */
/*-------------------------------------------------------------------------
* Function: check_options
diff --git a/tools/lib/h5diff_attr.c b/tools/lib/h5diff_attr.c
index 2cf6539..ad6f45b 100644
--- a/tools/lib/h5diff_attr.c
+++ b/tools/lib/h5diff_attr.c
@@ -79,8 +79,7 @@ hsize_t diff_attr(hid_t loc1_id,
if(oinfo1.num_attrs != oinfo2.num_attrs)
return 1;
- for( u = 0; u < (unsigned)oinfo1.num_attrs; u++)
- {
+ for(u = 0; u < (unsigned)oinfo1.num_attrs; u++) {
/* reset buffers for every attribute, we might goto out and call free */
buf1 = NULL;
buf2 = NULL;
@@ -104,29 +103,29 @@ hsize_t diff_attr(hid_t loc1_id,
goto error;
/* get the datatypes */
- if ((ftype1_id = H5Aget_type(attr1_id)) < 0)
+ if((ftype1_id = H5Aget_type(attr1_id)) < 0)
goto error;
- if ((ftype2_id = H5Aget_type(attr2_id)) < 0)
+ if((ftype2_id = H5Aget_type(attr2_id)) < 0)
goto error;
- if ((mtype1_id = h5tools_get_native_type(ftype1_id))<0)
+ if((mtype1_id = h5tools_get_native_type(ftype1_id))<0)
goto error;
- if ((mtype2_id = h5tools_get_native_type(ftype2_id))<0)
+ if((mtype2_id = h5tools_get_native_type(ftype2_id))<0)
goto error;
- if ((msize1 = H5Tget_size(mtype1_id))==0)
+ if((msize1 = H5Tget_size(mtype1_id))==0)
goto error;
- if ((msize2 = H5Tget_size(mtype2_id))==0)
+ if((msize2 = H5Tget_size(mtype2_id))==0)
goto error;
/* get the dataspace */
- if ((space1_id = H5Aget_space(attr1_id)) < 0)
+ if((space1_id = H5Aget_space(attr1_id)) < 0)
goto error;
- if ((space2_id = H5Aget_space(attr2_id)) < 0)
+ if((space2_id = H5Aget_space(attr2_id)) < 0)
goto error;
/* get dimensions */
- if ( (rank1 = H5Sget_simple_extent_dims(space1_id, dims1, NULL)) < 0 )
+ if((rank1 = H5Sget_simple_extent_dims(space1_id, dims1, NULL)) < 0)
goto error;
- if ( (rank2 = H5Sget_simple_extent_dims(space2_id, dims2, NULL)) < 0 )
+ if((rank2 = H5Sget_simple_extent_dims(space2_id, dims2, NULL)) < 0)
goto error;
@@ -135,43 +134,28 @@ hsize_t diff_attr(hid_t loc1_id,
*----------------------------------------------------------------------
*/
- if ( msize1 != msize2
- ||
- diff_can_type(ftype1_id,
- ftype2_id,
- rank1,
- rank2,
- dims1,
- dims2,
- NULL,
- NULL,
- name1,
- name2,
- options,
- 0)!=1)
+ if(msize1 != msize2 ||
+ diff_can_type(ftype1_id, ftype2_id, rank1, rank2, dims1,
+ dims2, NULL, NULL, name1, name2, options, 0) != 1)
{
-
-
- if (H5Tclose(ftype1_id)<0)
+ if(H5Tclose(ftype1_id) < 0)
goto error;
- if (H5Tclose(ftype2_id)<0)
+ if(H5Tclose(ftype2_id) < 0)
goto error;
- if (H5Sclose(space1_id)<0)
+ if(H5Sclose(space1_id) < 0)
goto error;
- if (H5Sclose(space2_id)<0)
+ if(H5Sclose(space2_id) < 0)
goto error;
- if (H5Aclose(attr1_id)<0)
+ if(H5Aclose(attr1_id) < 0)
goto error;
- if (H5Aclose(attr2_id)<0)
+ if(H5Aclose(attr2_id) < 0)
goto error;
- if (H5Tclose(mtype1_id)<0)
+ if(H5Tclose(mtype1_id) < 0)
goto error;
- if (H5Tclose(mtype2_id)<0)
+ if(H5Tclose(mtype2_id) < 0)
goto error;
continue;
-
-
}
@@ -179,19 +163,19 @@ hsize_t diff_attr(hid_t loc1_id,
* read
*----------------------------------------------------------------------
*/
- nelmts1=1;
- for (j=0; j<rank1; j++)
- nelmts1*=dims1[j];
+ nelmts1 = 1;
+ for(j = 0; j < rank1; j++)
+ nelmts1 *= dims1[j];
- buf1=(void *) HDmalloc((unsigned)(nelmts1*msize1));
- buf2=(void *) HDmalloc((unsigned)(nelmts1*msize2));
- if ( buf1==NULL || buf2==NULL){
+ buf1 = (void *)HDmalloc((unsigned)(nelmts1 * msize1));
+ buf2 = (void *)HDmalloc((unsigned)(nelmts1 * msize2));
+ if(buf1 == NULL || buf2 == NULL) {
parallel_print( "cannot read into memory\n" );
goto error;
}
- if (H5Aread(attr1_id,mtype1_id,buf1)<0)
+ if(H5Aread(attr1_id,mtype1_id,buf1) < 0)
goto error;
- if (H5Aread(attr2_id,mtype2_id,buf2)<0)
+ if(H5Aread(attr2_id,mtype2_id,buf2) < 0)
goto error;
/* format output string */
@@ -205,63 +189,29 @@ hsize_t diff_attr(hid_t loc1_id,
/* always print name */
/* verbose (-v) and report (-r) mode */
- if(options->m_verbose || options->m_report)
- {
- do_print_objname ("attribute", np1, np2);
- nfound = diff_array(buf1,
- buf2,
- nelmts1,
- (hsize_t)0,
- rank1,
- dims1,
- options,
- np1,
- np2,
- mtype1_id,
- attr1_id,
- attr2_id);
- print_found(nfound);
+ if(options->m_verbose || options->m_report) {
+ do_print_objname("attribute", np1, np2);
+ nfound = diff_array(buf1, buf2, nelmts1, (hsize_t)0, rank1, dims1,
+ options, np1, np2, mtype1_id, attr1_id, attr2_id);
+ print_found(nfound);
}
/* quiet mode (-q), just count differences */
- else if(options->m_quiet)
- {
- nfound = diff_array(buf1,
- buf2,
- nelmts1,
- (hsize_t)0,
- rank1,
- dims1,
- options,
- np1,
- np2,
- mtype1_id,
- attr1_id,
- attr2_id);
+ else if(options->m_quiet) {
+ nfound = diff_array(buf1, buf2, nelmts1, (hsize_t)0, rank1, dims1,
+ options, np1, np2, mtype1_id, attr1_id, attr2_id);
}
/* the rest (-c, none, ...) */
- else
- {
- nfound = diff_array(buf1,
- buf2,
- nelmts1,
- (hsize_t)0,
- rank1,
- dims1,
- options,
- np1,
- np2,
- mtype1_id,
- attr1_id,
- attr2_id);
+ else {
+ nfound = diff_array(buf1, buf2, nelmts1, (hsize_t)0, rank1, dims1,
+ options, np1, np2, mtype1_id, attr1_id, attr2_id);
/* not comparable, no display the different number */
- if (!options->not_cmp && nfound)
- {
- do_print_objname ("attribute", np1, np2);
+ if(!options->not_cmp && nfound) {
+ do_print_objname("attribute", np1, np2);
print_found(nfound);
- }
- }
+ } /* end if */
+ } /* end else */
/*----------------------------------------------------------------------
@@ -269,51 +219,61 @@ hsize_t diff_attr(hid_t loc1_id,
*----------------------------------------------------------------------
*/
- if (H5Tclose(ftype1_id)<0)
+ /* Free buf1 and buf2, being careful to reclaim any VL data first */
+ if(TRUE == H5Tdetect_class(mtype1_id, H5T_VLEN))
+ H5Dvlen_reclaim(mtype1_id, space1_id, H5P_DEFAULT, buf1);
+ HDfree(buf1);
+ buf1 = NULL;
+ if(TRUE == H5Tdetect_class(mtype2_id, H5T_VLEN))
+ H5Dvlen_reclaim(mtype2_id, space2_id, H5P_DEFAULT, buf2);
+ HDfree(buf2);
+ buf2 = NULL;
+
+ if(H5Tclose(ftype1_id) < 0)
goto error;
- if (H5Tclose(ftype2_id)<0)
+ if(H5Tclose(ftype2_id) < 0)
goto error;
- if (H5Sclose(space1_id)<0)
+ if(H5Sclose(space1_id) < 0)
goto error;
- if (H5Sclose(space2_id)<0)
+ if(H5Sclose(space2_id) < 0)
goto error;
- if (H5Aclose(attr1_id)<0)
+ if(H5Aclose(attr1_id) < 0)
goto error;
- if (H5Aclose(attr2_id)<0)
+ if(H5Aclose(attr2_id) < 0)
goto error;
- if (H5Tclose(mtype1_id)<0)
+ if(H5Tclose(mtype1_id) < 0)
goto error;
- if (H5Tclose(mtype2_id)<0)
+ if(H5Tclose(mtype2_id) < 0)
goto error;
- if (buf1)
- HDfree(buf1);
- if (buf2)
- HDfree(buf2);
-
nfound_total += nfound;
- } /* u */
+ } /* u */
- return nfound_total;
+ return nfound_total;
error:
- H5E_BEGIN_TRY {
- H5Tclose(ftype1_id);
- H5Tclose(ftype2_id);
- H5Tclose(mtype1_id);
- H5Tclose(mtype2_id);
- H5Sclose(space1_id);
- H5Sclose(space2_id);
- H5Aclose(attr1_id);
- H5Aclose(attr2_id);
- if (buf1)
- HDfree(buf1);
- if (buf2)
- HDfree(buf2);
- } H5E_END_TRY;
-
- options->err_stat=1;
- return nfound_total;
+ H5E_BEGIN_TRY {
+ if(buf1) {
+ if(TRUE == H5Tdetect_class(mtype1_id, H5T_VLEN))
+ H5Dvlen_reclaim(mtype1_id, space1_id, H5P_DEFAULT, buf1);
+ HDfree(buf1);
+ } /* end if */
+ if(buf2) {
+ if(TRUE == H5Tdetect_class(mtype2_id, H5T_VLEN))
+ H5Dvlen_reclaim(mtype2_id, space2_id, H5P_DEFAULT, buf2);
+ HDfree(buf2);
+ } /* end if */
+ H5Tclose(ftype1_id);
+ H5Tclose(ftype2_id);
+ H5Tclose(mtype1_id);
+ H5Tclose(mtype2_id);
+ H5Sclose(space1_id);
+ H5Sclose(space2_id);
+ H5Aclose(attr1_id);
+ H5Aclose(attr2_id);
+ } H5E_END_TRY;
+
+ options->err_stat = 1;
+ return nfound_total;
}
-