summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorLeon Arber <larber@ncsa.uiuc.edu>2006-11-08 01:52:54 (GMT)
committerLeon Arber <larber@ncsa.uiuc.edu>2006-11-08 01:52:54 (GMT)
commit77763447fdce64159edc73b02f28937a8bd4af69 (patch)
tree6a568790f006ebaea5d0a97d566cdff79c6b9749 /src
parent665f42f9e0d7b84bddbca2ff45b276b45eb76654 (diff)
downloadhdf5-77763447fdce64159edc73b02f28937a8bd4af69.zip
hdf5-77763447fdce64159edc73b02f28937a8bd4af69.tar.gz
hdf5-77763447fdce64159edc73b02f28937a8bd4af69.tar.bz2
[svn-r12879] Purpose: Bug fix
Description: Fix a few memory-related bugs in the data transform code. Tested: kagiso (for real this time) w/ valgrind 3.2.1
Diffstat (limited to 'src')
-rw-r--r--src/H5Pdxpl.c4
-rw-r--r--src/H5Ztrans.c31
2 files changed, 22 insertions, 13 deletions
diff --git a/src/H5Pdxpl.c b/src/H5Pdxpl.c
index 4fb2b07..84ac73c 100644
--- a/src/H5Pdxpl.c
+++ b/src/H5Pdxpl.c
@@ -573,6 +573,10 @@ H5Pset_data_transform(hid_t plist_id, const char* expression)
if(NULL == (plist = H5P_object_verify(plist_id,H5P_DATASET_XFER)))
HGOTO_ERROR(H5E_ATOM, H5E_BADATOM, FAIL, "can't find object for ID")
+ /* See if a data transform is already set, and free it if it is */
+ if(H5P_get(plist, H5D_XFER_XFORM_NAME, &data_xform_prop) >= 0)
+ H5Z_xform_destroy(data_xform_prop);
+
/* Create data transform info from expression */
if(NULL == (data_xform_prop = H5Z_xform_create(expression)))
HGOTO_ERROR(H5E_PLINE, H5E_NOSPACE, FAIL, "unable to create data transform info")
diff --git a/src/H5Ztrans.c b/src/H5Ztrans.c
index 5883058..932a671 100644
--- a/src/H5Ztrans.c
+++ b/src/H5Ztrans.c
@@ -665,7 +665,7 @@ H5Z_parse_term(H5Z_token *current, H5Z_datval_ptrs* dat_val_pointers)
new_node->rchild = H5Z_parse_factor(current, dat_val_pointers);
if (!new_node->rchild) {
- H5Z_xform_destroy_parse_tree(term);
+ H5Z_xform_destroy_parse_tree(new_node);
HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, NULL, "Error parsing data transform expression")
}
@@ -685,7 +685,7 @@ H5Z_parse_term(H5Z_token *current, H5Z_datval_ptrs* dat_val_pointers)
term = new_node;
if (!new_node->rchild) {
- H5Z_xform_destroy_parse_tree(term);
+ H5Z_xform_destroy_parse_tree(new_node);
HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, NULL, "Error parsing data transform expression")
}
break;
@@ -871,16 +871,17 @@ done:
static H5Z_node *
H5Z_new_node(H5Z_token_type type)
{
- H5Z_node* new_node;
-
- FUNC_ENTER_NOAPI_NOFUNC(H5Z_new_node)
+ H5Z_node* ret_value = NULL;
- new_node = H5MM_calloc(sizeof(H5Z_node));
- assert(new_node);
+ FUNC_ENTER_NOAPI(H5Z_new_node, NULL);
- new_node->type = type;
+ ret_value = H5MM_calloc(sizeof(H5Z_node));
+ if(ret_value == NULL)
+ HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "Ran out of memory trying to allocate space for nodes in the parse tree")
- FUNC_LEAVE_NOAPI(new_node);
+ ret_value->type = type;
+done:
+ FUNC_LEAVE_NOAPI(ret_value);
}
@@ -974,8 +975,9 @@ H5Z_xform_eval(H5Z_data_xform_t *data_xform_prop, void* array, size_t array_size
if(H5Z_xform_eval_full(tree, array_size, array_type, &res) < 0)
HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "error while performing data transform")
-
- HDmemcpy(array, res.value.dat_val, array_size * H5Tget_size(array_type));
+
+ if(data_xform_prop->dat_val_pointers->num_ptrs > 1)
+ HDmemcpy(array, res.value.dat_val, array_size * H5Tget_size(array_type));
/* Free the temporary arrays we used */
if(data_xform_prop->dat_val_pointers->num_ptrs > 1)
@@ -1320,7 +1322,6 @@ H5Z_do_op(H5Z_node* tree)
FUNC_ENTER_NOAPI_NOINIT_NOFUNC(H5Z_do_op)
-
if(tree->type == H5Z_XFORM_DIVIDE)
H5Z_XFORM_DO_OP3(/)
else if(tree->type == H5Z_XFORM_MULT)
@@ -1416,6 +1417,10 @@ done:
H5Z_xform_destroy_parse_tree(data_xform_prop->parse_root);
if(data_xform_prop->xform_exp)
H5MM_xfree(data_xform_prop->xform_exp);
+ if(count > 0 && data_xform_prop->dat_val_pointers->ptr_dat_val)
+ H5MM_xfree(data_xform_prop->dat_val_pointers->ptr_dat_val);
+ if(data_xform_prop->dat_val_pointers)
+ H5MM_xfree(data_xform_prop->dat_val_pointers);
H5MM_xfree(data_xform_prop);
} /* end if */
} /* end if */
@@ -1449,7 +1454,7 @@ H5Z_xform_destroy(H5Z_data_xform_t *data_xform_prop)
FUNC_ENTER_NOAPI_NOFUNC(H5Z_xform_destroy)
if(data_xform_prop) {
- /* Destroy the parse tree */
+ /* Destroy the parse tree */
H5Z_xform_destroy_parse_tree(data_xform_prop->parse_root);
/* Free the expression */