summaryrefslogtreecommitdiffstats
path: root/tools/src
diff options
context:
space:
mode:
authorAllen Byrne <byrn@hdfgroup.org>2017-10-18 19:03:27 (GMT)
committerAllen Byrne <byrn@hdfgroup.org>2017-10-18 19:03:27 (GMT)
commitcf3342f8fc53108e831b208d8ccb48628fb23e51 (patch)
treebfaab707066a9625899fb93cc2f300dfed0ee2f9 /tools/src
parent78a5870680770a8827c0e1e805688be30d1a33a7 (diff)
downloadhdf5-cf3342f8fc53108e831b208d8ccb48628fb23e51.zip
hdf5-cf3342f8fc53108e831b208d8ccb48628fb23e51.tar.gz
hdf5-cf3342f8fc53108e831b208d8ccb48628fb23e51.tar.bz2
Fix tools error handling and valgrind issues
Diffstat (limited to 'tools/src')
-rw-r--r--tools/src/h5repack/h5repack.c17
-rw-r--r--tools/src/h5repack/h5repack_copy.c21
-rw-r--r--tools/src/h5repack/h5repack_refs.c32
3 files changed, 44 insertions, 26 deletions
diff --git a/tools/src/h5repack/h5repack.c b/tools/src/h5repack/h5repack.c
index eaca0a5..14b9461 100644
--- a/tools/src/h5repack/h5repack.c
+++ b/tools/src/h5repack/h5repack.c
@@ -227,7 +227,6 @@ hid_t copy_named_datatype(hid_t type_in, hid_t fidout,
/* Stack already exists, search for the datatype */
while (dt && dt->addr_in != oinfo.addr)
dt = dt->next;
-
dt_ret = dt;
}
else {
@@ -286,7 +285,7 @@ hid_t copy_named_datatype(hid_t type_in, hid_t fidout,
/* Increment the ref count on id_out, because the calling function will try to close it */
if(H5Iinc_ref(ret_value) < 0)
- ret_value = -1;
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Iinc_ref failed");
done:
return ret_value;
@@ -426,7 +425,8 @@ copy_attr(hid_t loc_in, hid_t loc_out, named_dt_t **named_dt_head_p,
base_type = H5Tget_super(ftype_id);
is_ref = (is_ref || (H5Tget_class(base_type) == H5T_REFERENCE));
- H5Tclose(base_type);
+ if (H5Tclose(base_type) < 0)
+ H5TOOLS_INFO(H5E_tools_min_id_g, "H5Tclose base_type failed");
}
if (type_class == H5T_COMPOUND) {
@@ -435,7 +435,8 @@ copy_attr(hid_t loc_in, hid_t loc_out, named_dt_t **named_dt_head_p,
for (j = 0; j < nmembers; j++) {
hid_t mtid = H5Tget_member_type(wtype_id, (unsigned)j);
H5T_class_t mtclass = H5Tget_class(mtid);
- H5Tclose(mtid);
+ if (H5Tclose(mtid) < 0)
+ H5TOOLS_INFO(H5E_tools_min_id_g, "H5Tclose mtid failed");
if (mtclass == H5T_REFERENCE) {
is_ref = 1;
@@ -486,17 +487,19 @@ copy_attr(hid_t loc_in, hid_t loc_out, named_dt_t **named_dt_head_p,
* close
*-------------------------------------------------------------------------
*/
- if (H5Aclose(attr_out) < 0)
- HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Aclose failed");
if (H5Sclose(space_id) < 0)
HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Sclose failed");
+ space_id = -1;
if (H5Tclose(wtype_id) < 0)
HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Tclose failed");
+ wtype_id = -1;
if (H5Tclose(ftype_id) < 0)
HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Tclose failed");
+ ftype_id = -1;
if (H5Aclose(attr_id) < 0)
HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Aclose failed");
- } /* u */
+ attr_id = -1;
+ } /* for u */
done:
H5E_BEGIN_TRY {
diff --git a/tools/src/h5repack/h5repack_copy.c b/tools/src/h5repack/h5repack_copy.c
index 7c3dfa5..b043047 100644
--- a/tools/src/h5repack/h5repack_copy.c
+++ b/tools/src/h5repack/h5repack_copy.c
@@ -1175,6 +1175,7 @@ int do_copy_objects(hid_t fidin, hid_t fidout, trav_table_t *travt,
HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Tclose failed");
if (H5Tclose(type_out) < 0)
HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Tclose failed");
+ type_out = -1; /* named datatypes stack, named_dt_head, manages allocation */
break;
@@ -1205,6 +1206,18 @@ int do_copy_objects(hid_t fidin, hid_t fidout, trav_table_t *travt,
} /* end if */
done:
+
+ /* Finalize (link) the stack of named datatypes (if any) first
+ * because of reference counting */
+ if (0 == ret_value && named_dt_head != NULL) {
+ if (named_datatype_free(&named_dt_head, 0) < 0)
+ H5TOOLS_INFO(H5E_tools_min_id_g, "named_datatype_free failed");
+ }
+ else
+ H5E_BEGIN_TRY {
+ named_datatype_free(&named_dt_head, 1);
+ } H5E_END_TRY;
+
H5E_BEGIN_TRY
{
H5Gclose(grp_in);
@@ -1227,14 +1240,6 @@ done:
if (hslab_buf != NULL)
HDfree(hslab_buf);
- /* Finalize (link) the stack of named datatypes (if any) */
- if (0 == ret_value && named_dt_head != NULL)
- named_datatype_free(&named_dt_head, 0);
- else
- H5E_BEGIN_TRY {
- named_datatype_free(&named_dt_head, 1);
- } H5E_END_TRY;
-
return ret_value;
}
diff --git a/tools/src/h5repack/h5repack_refs.c b/tools/src/h5repack/h5repack_refs.c
index 376ab92..14294ea 100644
--- a/tools/src/h5repack/h5repack_refs.c
+++ b/tools/src/h5repack/h5repack_refs.c
@@ -189,7 +189,8 @@ int do_copy_refobjs(hid_t fidin,
refname);
}
} /*refname*/
- H5Oclose(refobj_id);
+ if (H5Oclose(refobj_id) < 0)
+ H5TOOLS_INFO(H5E_tools_min_id_g, "H5Oclose refob failed");
} /* u */
} /*nelmts*/
@@ -276,7 +277,8 @@ int do_copy_refobjs(hid_t fidin,
refname);
}
} /*refname*/
- H5Oclose(refobj_id);
+ if (H5Oclose(refobj_id) < 0)
+ H5TOOLS_INFO(H5E_tools_min_id_g, "H5Oclose refobj_id failed");
} /* u */
} /*nelmts*/
@@ -377,7 +379,8 @@ int do_copy_refobjs(hid_t fidin,
* This function is paired with copy_named_datatype() which is called
* in copy_attr(), so need to free.
*/
- named_datatype_free(&named_dt_head, 0);
+ if (named_datatype_free(&named_dt_head, 0) < 0)
+ H5TOOLS_INFO(H5E_tools_min_id_g, "named_datatype_free failed");
return ret_value;
@@ -392,7 +395,7 @@ done:
H5Tclose(ftype_id);
H5Tclose(mtype_id);
H5Tclose(type_in);
- named_datatype_free(&named_dt_head, 0);
+ named_datatype_free(&named_dt_head, 1);
} H5E_END_TRY;
return ret_value;
@@ -483,7 +486,8 @@ static int copy_refs_attr(hid_t loc_in,
base_type = H5Tget_super(ftype_id);
is_ref_vlen = (H5Tget_class(base_type) == H5T_REFERENCE);
msize = H5Tget_size(base_type);
- H5Tclose(base_type);
+ if (H5Tclose(base_type) < 0)
+ H5TOOLS_INFO(H5E_tools_min_id_g, "H5Tclose base_type failed");
}
else if(type_class == H5T_ARRAY ) {
hid_t base_type;
@@ -491,7 +495,8 @@ static int copy_refs_attr(hid_t loc_in,
base_type = H5Tget_super(ftype_id);
is_ref_array = (H5Tget_class(base_type) == H5T_REFERENCE);
msize = H5Tget_size(base_type);
- H5Tclose(base_type);
+ if (H5Tclose(base_type) < 0)
+ H5TOOLS_INFO(H5E_tools_min_id_g, "H5Tclose base_type failed");
}
else if(type_class == H5T_COMPOUND) {
int nmembers = H5Tget_nmembers(ftype_id) ;
@@ -511,7 +516,8 @@ static int copy_refs_attr(hid_t loc_in,
ref_comp_size[ref_comp_field_n] = H5Tget_size(mtid);
ref_comp_field_n++;
}
- H5Tclose(mtid);
+ if (H5Tclose(mtid) < 0)
+ H5TOOLS_INFO(H5E_tools_min_id_g, "H5Tclose mtid failed");
}
/* if compound don't contain reference type member, free the above
@@ -533,9 +539,12 @@ static int copy_refs_attr(hid_t loc_in,
is_ref_comp = (ref_comp_field_n > 0);
if (!(is_ref || is_ref_vlen || is_ref_array || is_ref_comp)) {
- H5Tclose(mtype_id);
- H5Tclose(ftype_id);
- H5Aclose(attr_id);
+ if (H5Tclose(mtype_id) < 0)
+ H5TOOLS_INFO(H5E_tools_min_id_g, "H5Tclose mtype_id failed");
+ if (H5Tclose(ftype_id) < 0)
+ H5TOOLS_INFO(H5E_tools_min_id_g, "H5Tclose ftype_id failed");
+ if (H5Aclose(attr_id) < 0)
+ H5TOOLS_INFO(H5E_tools_min_id_g, "H5Aclose attr_id failed");
continue;
}
@@ -568,7 +577,8 @@ static int copy_refs_attr(hid_t loc_in,
base_type = H5Tget_super(ftype_id);
msize = H5Tget_size(base_type);
- H5Tclose(base_type);
+ if (H5Tclose(base_type) < 0)
+ H5TOOLS_INFO(H5E_tools_min_id_g, "H5Tclose base_type failed");
array_rank = (unsigned)H5Tget_array_ndims(mtype_id);
H5Tget_array_dims2(mtype_id, array_dims);