[svn-r28797] Description:

Clean up another round of memory allocation mis-matches.

Tested on:
    Linux/32 2.6.x (jam) w/serial
    MacOSX/64 10.11.2 (amazon) w/serial & parallel
This commit is contained in:
Quincey Koziol 2016-01-04 22:28:43 -05:00
parent 3e0e79aa6e
commit 4c5bb2b8db
9 changed files with 54 additions and 64 deletions

View File

@ -614,7 +614,7 @@ H5B2_find(H5B2_t *bt2, hid_t dxpl_id, void *udata, H5B2_found_t op,
if(idx == 0) {
if(H5B2_POS_LEFT == curr_pos || H5B2_POS_ROOT == curr_pos) {
if(hdr->min_native_rec == NULL)
if(NULL == (hdr->min_native_rec = (uint8_t *)HDmalloc(hdr->cls->nrec_size)))
if(NULL == (hdr->min_native_rec = (uint8_t *)H5MM_malloc(hdr->cls->nrec_size)))
HGOTO_ERROR(H5E_BTREE, H5E_CANTALLOC, FAIL, "memory allocation failed for v2 B-tree min record info")
HDmemcpy(hdr->min_native_rec, H5B2_LEAF_NREC(leaf, hdr, idx), hdr->cls->nrec_size);
} /* end if */
@ -622,7 +622,7 @@ H5B2_find(H5B2_t *bt2, hid_t dxpl_id, void *udata, H5B2_found_t op,
if(idx == (unsigned)(leaf->nrec - 1)) {
if(H5B2_POS_RIGHT == curr_pos || H5B2_POS_ROOT == curr_pos) {
if(hdr->max_native_rec == NULL)
if(NULL == (hdr->max_native_rec = (uint8_t *)HDmalloc(hdr->cls->nrec_size)))
if(NULL == (hdr->max_native_rec = (uint8_t *)H5MM_malloc(hdr->cls->nrec_size)))
HGOTO_ERROR(H5E_BTREE, H5E_CANTALLOC, FAIL, "memory allocation failed for v2 B-tree max record info")
HDmemcpy(hdr->max_native_rec, H5B2_LEAF_NREC(leaf, hdr, idx), hdr->cls->nrec_size);
} /* end if */
@ -1224,7 +1224,7 @@ H5B2_modify(H5B2_t *bt2, hid_t dxpl_id, void *udata, H5B2_modify_t op,
if(idx == 0) {
if(H5B2_POS_LEFT == curr_pos || H5B2_POS_ROOT == curr_pos) {
if(hdr->min_native_rec == NULL)
if(NULL == (hdr->min_native_rec = (uint8_t *)HDmalloc(hdr->cls->nrec_size)))
if(NULL == (hdr->min_native_rec = (uint8_t *)H5MM_malloc(hdr->cls->nrec_size)))
HGOTO_ERROR(H5E_BTREE, H5E_CANTALLOC, FAIL, "memory allocation failed for v2 B-tree min record info")
HDmemcpy(hdr->min_native_rec, H5B2_LEAF_NREC(leaf, hdr, idx), hdr->cls->nrec_size);
} /* end if */
@ -1232,7 +1232,7 @@ H5B2_modify(H5B2_t *bt2, hid_t dxpl_id, void *udata, H5B2_modify_t op,
if(idx == (unsigned)(leaf->nrec - 1)) {
if(H5B2_POS_RIGHT == curr_pos || H5B2_POS_ROOT == curr_pos) {
if(hdr->max_native_rec == NULL)
if(NULL == (hdr->max_native_rec = (uint8_t *)HDmalloc(hdr->cls->nrec_size)))
if(NULL == (hdr->max_native_rec = (uint8_t *)H5MM_malloc(hdr->cls->nrec_size)))
HGOTO_ERROR(H5E_BTREE, H5E_CANTALLOC, FAIL, "memory allocation failed for v2 B-tree max record info")
HDmemcpy(hdr->max_native_rec, H5B2_LEAF_NREC(leaf, hdr, idx), hdr->cls->nrec_size);
} /* end if */

View File

@ -619,14 +619,10 @@ H5B2__hdr_free(H5B2_hdr_t *hdr)
} /* end if */
/* Release the min & max record info, if set */
if(hdr->min_native_rec) {
HDfree(hdr->min_native_rec);
hdr->min_native_rec = NULL;
} /* end if */
if(hdr->max_native_rec) {
HDfree(hdr->max_native_rec);
hdr->max_native_rec = NULL;
} /* end if */
if(hdr->min_native_rec)
hdr->min_native_rec = H5MM_free(hdr->min_native_rec);
if(hdr->max_native_rec)
hdr->max_native_rec = H5MM_free(hdr->max_native_rec);
/* Free B-tree header info */
hdr = H5FL_FREE(H5B2_hdr_t, hdr);

View File

@ -1640,7 +1640,7 @@ H5B2__insert_leaf(H5B2_hdr_t *hdr, hid_t dxpl_id, H5B2_node_ptr_t *curr_node_ptr
if(idx == 0) {
if(H5B2_POS_LEFT == curr_pos || H5B2_POS_ROOT == curr_pos) {
if(hdr->min_native_rec == NULL)
if(NULL == (hdr->min_native_rec = (uint8_t *)HDmalloc(hdr->cls->nrec_size)))
if(NULL == (hdr->min_native_rec = (uint8_t *)H5MM_malloc(hdr->cls->nrec_size)))
HGOTO_ERROR(H5E_BTREE, H5E_CANTALLOC, FAIL, "memory allocation failed for v2 B-tree min record info")
HDmemcpy(hdr->min_native_rec, H5B2_LEAF_NREC(leaf, hdr, idx), hdr->cls->nrec_size);
} /* end if */
@ -1648,7 +1648,7 @@ H5B2__insert_leaf(H5B2_hdr_t *hdr, hid_t dxpl_id, H5B2_node_ptr_t *curr_node_ptr
if(idx == (unsigned)(leaf->nrec - 1)) {
if(H5B2_POS_RIGHT == curr_pos || H5B2_POS_ROOT == curr_pos) {
if(hdr->max_native_rec == NULL)
if(NULL == (hdr->max_native_rec = (uint8_t *)HDmalloc(hdr->cls->nrec_size)))
if(NULL == (hdr->max_native_rec = (uint8_t *)H5MM_malloc(hdr->cls->nrec_size)))
HGOTO_ERROR(H5E_BTREE, H5E_CANTALLOC, FAIL, "memory allocation failed for v2 B-tree max record info")
HDmemcpy(hdr->max_native_rec, H5B2_LEAF_NREC(leaf, hdr, idx), hdr->cls->nrec_size);
} /* end if */
@ -1929,7 +1929,7 @@ H5B2__update_leaf(H5B2_hdr_t *hdr, hid_t dxpl_id, H5B2_node_ptr_t *curr_node_ptr
if(idx == 0) {
if(H5B2_POS_LEFT == curr_pos || H5B2_POS_ROOT == curr_pos) {
if(hdr->min_native_rec == NULL)
if(NULL == (hdr->min_native_rec = (uint8_t *)HDmalloc(hdr->cls->nrec_size)))
if(NULL == (hdr->min_native_rec = (uint8_t *)H5MM_malloc(hdr->cls->nrec_size)))
HGOTO_ERROR(H5E_BTREE, H5E_CANTALLOC, FAIL, "memory allocation failed for v2 B-tree min record info")
HDmemcpy(hdr->min_native_rec, H5B2_LEAF_NREC(leaf, hdr, idx), hdr->cls->nrec_size);
} /* end if */
@ -1937,7 +1937,7 @@ H5B2__update_leaf(H5B2_hdr_t *hdr, hid_t dxpl_id, H5B2_node_ptr_t *curr_node_ptr
if(idx == (unsigned)(leaf->nrec - 1)) {
if(H5B2_POS_RIGHT == curr_pos || H5B2_POS_ROOT == curr_pos) {
if(hdr->max_native_rec == NULL)
if(NULL == (hdr->max_native_rec = (uint8_t *)HDmalloc(hdr->cls->nrec_size)))
if(NULL == (hdr->max_native_rec = (uint8_t *)H5MM_malloc(hdr->cls->nrec_size)))
HGOTO_ERROR(H5E_BTREE, H5E_CANTALLOC, FAIL, "memory allocation failed for v2 B-tree max record info")
HDmemcpy(hdr->max_native_rec, H5B2_LEAF_NREC(leaf, hdr, idx), hdr->cls->nrec_size);
} /* end if */
@ -2552,18 +2552,14 @@ H5B2__remove_leaf(H5B2_hdr_t *hdr, hid_t dxpl_id, H5B2_node_ptr_t *curr_node_ptr
/* (Don't use 'else' for the idx check, to allow for root leaf node) */
if(idx == 0) {
if(H5B2_POS_LEFT == curr_pos || H5B2_POS_ROOT == curr_pos) {
if(hdr->min_native_rec) {
HDfree(hdr->min_native_rec);
hdr->min_native_rec = NULL;
} /* end if */
if(hdr->min_native_rec)
hdr->min_native_rec = H5MM_free(hdr->min_native_rec);
} /* end if */
} /* end if */
if(idx == (unsigned)(leaf->nrec - 1)) {
if(H5B2_POS_RIGHT == curr_pos || H5B2_POS_ROOT == curr_pos) {
if(hdr->max_native_rec) {
HDfree(hdr->max_native_rec);
hdr->max_native_rec = NULL;
} /* end if */
if(hdr->max_native_rec)
hdr->max_native_rec = H5MM_free(hdr->max_native_rec);
} /* end if */
} /* end if */
} /* end if */
@ -2867,18 +2863,14 @@ H5B2__remove_leaf_by_idx(H5B2_hdr_t *hdr, hid_t dxpl_id,
/* (Don't use 'else' for the idx check, to allow for root leaf node) */
if(idx == 0) {
if(H5B2_POS_LEFT == curr_pos || H5B2_POS_ROOT == curr_pos) {
if(hdr->min_native_rec) {
HDfree(hdr->min_native_rec);
hdr->min_native_rec = NULL;
} /* end if */
if(hdr->min_native_rec)
hdr->min_native_rec = H5MM_free(hdr->min_native_rec);
} /* end if */
} /* end if */
if(idx == (unsigned)(leaf->nrec - 1)) {
if(H5B2_POS_RIGHT == curr_pos || H5B2_POS_ROOT == curr_pos) {
if(hdr->max_native_rec) {
HDfree(hdr->max_native_rec);
hdr->max_native_rec = NULL;
} /* end if */
if(hdr->max_native_rec)
hdr->max_native_rec = H5MM_free(hdr->max_native_rec);
} /* end if */
} /* end if */
} /* end if */

View File

@ -3746,7 +3746,7 @@ H5D__chunk_allocate(const H5D_t *dset, hid_t dxpl_id, hbool_t full_overwrite,
write collectively at the end */
/* allocate/resize address array if no more space left */
if(0 == chunk_info.num_io % 1024)
if(NULL == (chunk_info.addr = (haddr_t *)HDrealloc(chunk_info.addr, (chunk_info.num_io + 1024) * sizeof(haddr_t))))
if(NULL == (chunk_info.addr = (haddr_t *)H5MM_realloc(chunk_info.addr, (chunk_info.num_io + 1024) * sizeof(haddr_t))))
HGOTO_ERROR(H5E_DATASET, H5E_CANTALLOC, FAIL, "memory allocation failed for chunk addresses")
/* Store the chunk's address for later */
@ -3813,7 +3813,7 @@ done:
#ifdef H5_HAVE_PARALLEL
if(using_mpi && chunk_info.addr)
HDfree(chunk_info.addr);
H5MM_free(chunk_info.addr);
#endif
FUNC_LEAVE_NOAPI_TAG(ret_value, FAIL)

View File

@ -1680,7 +1680,6 @@ H5D__obtain_mpio_mode(H5D_io_info_t* io_info, H5D_chunk_map_t *fm,
MPI_Comm comm;
int ic, root;
int mpi_code;
hbool_t mem_cleanup = FALSE;
#ifdef H5_HAVE_INSTRUMENTED_LIBRARY
int new_value;
htri_t check_prop;
@ -1715,12 +1714,14 @@ H5D__obtain_mpio_mode(H5D_io_info_t* io_info, H5D_chunk_map_t *fm,
threshold_nproc_per_chunk = mpi_size * percent_nproc_per_chunk/100;
/* Allocate memory */
io_mode_info = (uint8_t *)H5MM_calloc(total_chunks);
mergebuf = H5MM_malloc((sizeof(haddr_t) + 1) * total_chunks);
if(NULL == (io_mode_info = (uint8_t *)H5MM_calloc(total_chunks)))
HGOTO_ERROR(H5E_DATASET, H5E_CANTALLOC, FAIL, "couldn't allocate I/O mode info buffer")
if(NULL == (mergebuf = H5MM_malloc((sizeof(haddr_t) + 1) * total_chunks)))
HGOTO_ERROR(H5E_DATASET, H5E_CANTALLOC, FAIL, "couldn't allocate mergebuf buffer")
tempbuf = mergebuf + total_chunks;
if(mpi_rank == root)
recv_io_mode_info = (uint8_t *)H5MM_malloc(total_chunks * mpi_size);
mem_cleanup = TRUE;
if(NULL == (recv_io_mode_info = (uint8_t *)H5MM_malloc(total_chunks * mpi_size)))
HGOTO_ERROR(H5E_DATASET, H5E_CANTALLOC, FAIL, "couldn't allocate recv I/O mode info buffer")
/* Obtain the regularity and selection information for all chunks in this process. */
chunk_node = H5SL_first(fm->sel_chunks);
@ -1742,11 +1743,12 @@ H5D__obtain_mpio_mode(H5D_io_info_t* io_info, H5D_chunk_map_t *fm,
/* pre-computing: calculate number of processes and
regularity of the selection occupied in each chunk */
nproc_per_chunk = (int*)H5MM_calloc(total_chunks * sizeof(int));
if(NULL == (nproc_per_chunk = (int*)H5MM_calloc(total_chunks * sizeof(int))))
HGOTO_ERROR(H5E_DATASET, H5E_CANTALLOC, FAIL, "couldn't allocate nproc_per_chunk buffer")
/* calculating the chunk address */
if(H5D__chunk_addrmap(io_info, chunk_addr) < 0) {
HDfree(nproc_per_chunk);
H5MM_free(nproc_per_chunk);
HGOTO_ERROR(H5E_DATASET, H5E_CANTGET, FAIL, "can't get chunk address")
} /* end if */
@ -1774,7 +1776,7 @@ H5D__obtain_mpio_mode(H5D_io_info_t* io_info, H5D_chunk_map_t *fm,
HDmemcpy(mergebuf, assign_io_mode, total_chunks);
HDmemcpy(tempbuf, chunk_addr, sizeof(haddr_t) * total_chunks);
HDfree(nproc_per_chunk);
H5MM_free(nproc_per_chunk);
} /* end if */
/* Broadcasting the MPI_IO option info. and chunk address info. */
@ -1824,11 +1826,13 @@ H5D__obtain_mpio_mode(H5D_io_info_t* io_info, H5D_chunk_map_t *fm,
#endif
done:
if(mem_cleanup) {
HDfree(io_mode_info);
HDfree(mergebuf);
if(mpi_rank == root)
HDfree(recv_io_mode_info);
if(io_mode_info)
H5MM_free(io_mode_info);
if(mergebuf)
H5MM_free(mergebuf);
if(recv_io_mode_info) {
HDassert(mpi_rank == root);
H5MM_free(recv_io_mode_info);
} /* end if */
FUNC_LEAVE_NOAPI(ret_value)

View File

@ -446,10 +446,10 @@ H5D__virtual_copy_layout(H5O_layout_t *layout)
/* Copy original source names */
if(NULL == (layout->storage.u.virt.list[i].source_file_name
= HDstrdup(orig_list[i].source_file_name)))
= H5MM_strdup(orig_list[i].source_file_name)))
HGOTO_ERROR(H5E_DATASET, H5E_RESOURCE, FAIL, "unable to duplicate source file name")
if(NULL == (layout->storage.u.virt.list[i].source_dset_name
= HDstrdup(orig_list[i].source_dset_name)))
= H5MM_strdup(orig_list[i].source_dset_name)))
HGOTO_ERROR(H5E_DATASET, H5E_RESOURCE, FAIL, "unable to duplicate source dataset name")
/* Copy source selection */
@ -488,7 +488,7 @@ H5D__virtual_copy_layout(H5O_layout_t *layout)
} /* end if */
else
if(NULL == (layout->storage.u.virt.list[i].source_dset.file_name
= HDstrdup(orig_list[i].source_dset.file_name)))
= H5MM_strdup(orig_list[i].source_dset.file_name)))
HGOTO_ERROR(H5E_DATASET, H5E_RESOURCE, FAIL, "unable to duplicate source file name")
} /* end if */
if(orig_list[i].source_dset.dset_name) {
@ -504,7 +504,7 @@ H5D__virtual_copy_layout(H5O_layout_t *layout)
} /* end if */
else
if(NULL == (layout->storage.u.virt.list[i].source_dset.dset_name
= HDstrdup(orig_list[i].source_dset.dset_name)))
= H5MM_strdup(orig_list[i].source_dset.dset_name)))
HGOTO_ERROR(H5E_DATASET, H5E_RESOURCE, FAIL, "unable to duplicate source dataset name")
} /* end if */
@ -1124,7 +1124,7 @@ H5D__virtual_copy_parsed_name(H5O_storage_virtual_name_seg_t **dst,
/* Duplicate name segment */
if(p_src->name_segment) {
if(NULL == ((*p_dst)->name_segment = HDstrdup(p_src->name_segment)))
if(NULL == ((*p_dst)->name_segment = H5MM_strdup(p_src->name_segment)))
HGOTO_ERROR(H5E_RESOURCE, H5E_CANTALLOC, FAIL, "unable to duplicate name segment")
} /* end if */

View File

@ -406,7 +406,7 @@ H5FD_log_fapl_copy(const void *_old_fa)
/* Deep copy the log file name */
if(old_fa->logfile != NULL)
if(NULL == (new_fa->logfile = H5MM_xstrdup(old_fa->logfile)))
if(NULL == (new_fa->logfile = H5MM_strdup(old_fa->logfile)))
HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "unable to allocate log file name")
/* Set return value */
@ -416,7 +416,7 @@ done:
if(NULL == ret_value)
if(new_fa) {
if(new_fa->logfile)
H5MM_free(new_fa->logfile);
new_fa->logfile = H5MM_free(new_fa->logfile);
H5MM_free(new_fa);
} /* end if */
@ -445,7 +445,7 @@ H5FD_log_fapl_free(void *_fa)
/* Free the fapl information */
if(fa->logfile)
H5MM_xfree(fa->logfile);
fa->logfile = H5MM_free(fa->logfile);
H5MM_xfree(fa);
FUNC_LEAVE_NOAPI(SUCCEED)
@ -594,7 +594,7 @@ H5FD_log_open(const char *name, unsigned flags, hid_t fapl_id, haddr_t maxaddr)
/* Get the flags for logging */
file->fa.flags = fa->flags;
if(fa->logfile)
file->fa.logfile = HDstrdup(fa->logfile);
file->fa.logfile = H5MM_strdup(fa->logfile);
else
file->fa.logfile = NULL;
file->fa.buf_size = fa->buf_size;
@ -798,10 +798,8 @@ H5FD_log_close(H5FD_t *_file)
HDfclose(file->logfp);
} /* end if */
if(file->fa.logfile) {
HDfree(file->fa.logfile);
file->fa.logfile = NULL;
}
if(file->fa.logfile)
file->fa.logfile = H5MM_free(file->fa.logfile);
/* Release the file info */
file = H5FL_FREE(H5FD_log_t, file);

View File

@ -463,7 +463,7 @@ H5O_copy_header_real(const H5O_loc_t *oloc_src, H5O_loc_t *oloc_dst /*out*/,
/* Allocate memory for "deleted" array. This array marks the message in
* the source that shouldn't be copied to the destination.
*/
if(NULL == (deleted = (hbool_t *)HDmalloc(sizeof(hbool_t) * oh_src->nmesgs)))
if(NULL == (deleted = (hbool_t *)H5MM_malloc(sizeof(hbool_t) * oh_src->nmesgs)))
HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed")
HDmemset(deleted, FALSE, sizeof(hbool_t) * oh_src->nmesgs);
@ -870,7 +870,7 @@ H5O_copy_header_real(const H5O_loc_t *oloc_src, H5O_loc_t *oloc_dst /*out*/,
done:
/* Free deleted array */
if(deleted)
HDfree(deleted);
H5MM_free(deleted);
/* Release pointer to source object header and its derived objects */
if(oh_src && H5O_unprotect(oloc_src, dxpl_id, oh_src, H5AC__NO_FLAGS_SET) < 0)

View File

@ -2227,9 +2227,9 @@ H5Pset_virtual(hid_t dcpl_id, hid_t vspace_id, const char *src_file_name,
HDmemset(ent, 0, sizeof(H5O_storage_virtual_ent_t)); /* Clear before starting to set up */
if(NULL == (ent->source_dset.virtual_select = H5S_copy(vspace, FALSE, TRUE)))
HGOTO_ERROR(H5E_PLIST, H5E_CANTCOPY, FAIL, "unable to copy virtual selection")
if(NULL == (ent->source_file_name = HDstrdup(src_file_name)))
if(NULL == (ent->source_file_name = H5MM_xstrdup(src_file_name)))
HGOTO_ERROR(H5E_PLIST, H5E_RESOURCE, FAIL, "can't duplicate source file name")
if(NULL == (ent->source_dset_name = HDstrdup(src_dset_name)))
if(NULL == (ent->source_dset_name = H5MM_xstrdup(src_dset_name)))
HGOTO_ERROR(H5E_PLIST, H5E_RESOURCE, FAIL, "can't duplicate source file name")
if(NULL == (ent->source_select = H5S_copy(src_space, FALSE, TRUE)))
HGOTO_ERROR(H5E_PLIST, H5E_CANTCOPY, FAIL, "unable to copy source selection")