diff options
Diffstat (limited to 'src/H5Aint.c')
-rw-r--r-- | src/H5Aint.c | 32 |
1 files changed, 10 insertions, 22 deletions
diff --git a/src/H5Aint.c b/src/H5Aint.c index 88c8b99..a89c1c9 100644 --- a/src/H5Aint.c +++ b/src/H5Aint.c @@ -150,33 +150,21 @@ H5A_compact_build_table_cb(H5O_t UNUSED *oh, H5O_mesg_t *mesg/*in,out*/, /* Re-allocate the table if necessary */ if(udata->curr_attr == udata->atable->nattrs) { - size_t i; - size_t n = MAX(1, 2 * udata->atable->nattrs); - H5A_t **table = (H5A_t **)H5FL_SEQ_CALLOC(H5A_t_ptr, n); - - /* Use attribute functions for operation to manage memory properly */ - for(i=0; i<udata->atable->nattrs; i++) { - table[i] = (H5A_t *)H5FL_CALLOC(H5A_t); - - if(NULL == H5A_copy(table[i], udata->atable->attrs[i])) - HGOTO_ERROR(H5E_ATTR, H5E_CANTCOPY, H5_ITER_ERROR, "can't copy attribute") - if(H5A_close(udata->atable->attrs[i]) < 0) - HGOTO_ERROR(H5E_ATTR, H5E_CANTCLOSEOBJ, H5_ITER_ERROR, "can't close attribute") - } - - if(udata->atable->nattrs) - udata->atable->attrs = (H5A_t **)H5FL_SEQ_FREE(H5A_t_ptr, udata->atable->attrs); + H5A_t **new_table; /* New table for attributes */ + size_t new_table_size; /* Number of attributes in new table */ - if(!table) + /* Allocate larger table */ + new_table_size = MAX(1, 2 * udata->atable->nattrs); + if(NULL == (new_table = (H5A_t **)H5FL_SEQ_REALLOC(H5A_t_ptr, udata->atable->attrs, new_table_size))) HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, H5_ITER_ERROR, "unable to extend attribute table") - udata->atable->attrs = table; - udata->atable->nattrs = n; + + /* Update table information in user data */ + udata->atable->attrs = new_table; + udata->atable->nattrs = new_table_size; } /* end if */ /* Copy attribute into table */ - udata->atable->attrs[udata->curr_attr] = (H5A_t *)H5FL_CALLOC(H5A_t); - - if(NULL == H5A_copy(udata->atable->attrs[udata->curr_attr], (const H5A_t *)mesg->native)) + if(NULL == (udata->atable->attrs[udata->curr_attr] = H5A_copy(NULL, (const H5A_t *)mesg->native))) HGOTO_ERROR(H5E_ATTR, H5E_CANTCOPY, H5_ITER_ERROR, "can't copy attribute") /* Assign [somewhat arbitrary] creation order value, if requested */ |