summaryrefslogtreecommitdiffstats
path: root/src/H5Oefl.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/H5Oefl.c')
-rw-r--r--src/H5Oefl.c58
1 files changed, 45 insertions, 13 deletions
diff --git a/src/H5Oefl.c b/src/H5Oefl.c
index 0eb4ba2..25cac88 100644
--- a/src/H5Oefl.c
+++ b/src/H5Oefl.c
@@ -262,27 +262,58 @@ H5O_efl_copy(const void *_mesg, void *_dest)
/* check args */
HDassert(mesg);
if(!dest) {
- if(NULL == (dest = (H5O_efl_t *)H5MM_calloc(sizeof(H5O_efl_t))) ||
- NULL == (dest->slot = (H5O_efl_entry_t *)H5MM_malloc(mesg->nalloc * sizeof(H5O_efl_entry_t))))
- HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed")
- } else if(dest->nalloc < mesg->nalloc) {
- H5MM_xfree(dest->slot);
- if(NULL == (dest->slot = (H5O_efl_entry_t *)H5MM_malloc(mesg->nalloc * sizeof(H5O_efl_entry_t))))
- HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed")
- }
+ if(NULL == (dest = (H5O_efl_t *)H5MM_calloc(sizeof(H5O_efl_t))))
+ HGOTO_ERROR(H5E_OHDR, H5E_CANTALLOC, NULL, "can't allocate efl message")
+ if(NULL == (dest->slot = (H5O_efl_entry_t *)H5MM_calloc(mesg->nalloc * sizeof(H5O_efl_entry_t))))
+ HGOTO_ERROR(H5E_OHDR, H5E_CANTALLOC, NULL, "can't allocate efl message slots")
+ } /* end if */
+ else if(dest->nalloc < mesg->nalloc) {
+ H5O_efl_entry_t *temp_slot; /* Temporary pointer to new slot information */
+
+ /* Allocate new 'slot' information */
+ if(NULL == (temp_slot = (H5O_efl_entry_t *)H5MM_calloc(mesg->nalloc * sizeof(H5O_efl_entry_t))))
+ HGOTO_ERROR(H5E_OHDR, H5E_CANTALLOC, NULL, "can't allocate efl message slots")
+
+ /* Release old 'slot' information */
+ for(u = 0; u < dest->nused; u++)
+ dest->slot[u].name = (char *)H5MM_xfree(dest->slot[u].name);
+ dest->slot = (H5O_efl_entry_t *)H5MM_xfree(dest->slot);
+
+ /* Point to new 'slot' information */
+ dest->slot = temp_slot;
+ } /* end if */
+ else {
+ /* Release old 'slot' information */
+ for(u = 0; u < dest->nused; u++)
+ dest->slot[u].name = (char *)H5MM_xfree(dest->slot[u].name);
+ } /* end else */
dest->heap_addr = mesg->heap_addr;
dest->nalloc = mesg->nalloc;
dest->nused = mesg->nused;
for(u = 0; u < mesg->nused; u++) {
dest->slot[u] = mesg->slot[u];
- dest->slot[u].name = H5MM_xstrdup(mesg->slot[u].name);
+ if(NULL == (dest->slot[u].name = H5MM_xstrdup(mesg->slot[u].name)))
+ HGOTO_ERROR(H5E_OHDR, H5E_CANTALLOC, NULL, "can't allocate efl message slot name")
} /* end for */
/* Set return value */
ret_value = dest;
done:
+ if(NULL == ret_value) {
+ if(dest && NULL == _dest) {
+ if(dest->slot) {
+ for(u = 0; u < mesg->nused; u++) {
+ if(dest->slot[u].name != NULL && dest->slot[u].name != mesg->slot[u].name)
+ dest->slot[u].name = (char *)H5MM_xfree(dest->slot[u].name);
+ } /* end for */
+ dest->slot = (H5O_efl_entry_t *)H5MM_xfree(dest->slot);
+ } /* end if */
+ dest = (H5O_efl_t *)H5MM_xfree(dest);
+ } /* end if */
+ } /* end if */
+
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5O_efl_copy() */
@@ -353,12 +384,13 @@ H5O_efl_reset(void *_mesg)
HDassert(mesg);
/* reset */
- for(u = 0; u < mesg->nused; u++)
- mesg->slot[u].name = (char *)H5MM_xfree(mesg->slot[u].name);
+ if(mesg->slot) {
+ for(u = 0; u < mesg->nused; u++)
+ mesg->slot[u].name = (char *)H5MM_xfree(mesg->slot[u].name);
+ mesg->slot = (H5O_efl_entry_t *)H5MM_xfree(mesg->slot);
+ } /* end if */
mesg->heap_addr = HADDR_UNDEF;
mesg->nused = mesg->nalloc = 0;
- if(mesg->slot)
- mesg->slot = (H5O_efl_entry_t *)H5MM_xfree(mesg->slot);
FUNC_LEAVE_NOAPI(SUCCEED)
} /* end H5O_efl_reset() */