summaryrefslogtreecommitdiffstats
path: root/src/H5HG.c
diff options
context:
space:
mode:
authorRobb Matzke <matzke@llnl.gov>1998-06-23 03:41:22 (GMT)
committerRobb Matzke <matzke@llnl.gov>1998-06-23 03:41:22 (GMT)
commit4bf629adc96541fda24bafbdde00fd4ff92be344 (patch)
tree8e6d57995ba50bafdf172df9d480bd99cdb1230e /src/H5HG.c
parent62607debf74800472572e65517ed284aef19a63c (diff)
downloadhdf5-4bf629adc96541fda24bafbdde00fd4ff92be344.zip
hdf5-4bf629adc96541fda24bafbdde00fd4ff92be344.tar.gz
hdf5-4bf629adc96541fda24bafbdde00fd4ff92be344.tar.bz2
[svn-r435] ./INSTALL
./INSTALL_MAINT ./README ./RELEASE Partially updated for second alpha, but haven't updated version numbers yet. ./src/H5.c ./src/H5A.c ./src/H5AC.c ./src/H5B.c ./src/H5D.c ./src/H5F.c ./src/H5Fcore.c ./src/H5Ffamily.c ./src/H5Fistore.c ./src/H5Fmpio.c ./src/H5Fsec2.c ./src/H5Fsplit.c ./src/H5Fstdio.c ./src/H5G.c ./src/H5Gnode.c ./src/H5HG.c ./src/H5HL.c ./src/H5I.c ./src/H5MM.c ./src/H5MMprivate.h ./src/H5O.c ./src/H5Oattr.c ./src/H5Ocomp.c ./src/H5Ocont.c ./src/H5Odtype.c ./src/H5Oefl.c ./src/H5Olayout.c ./src/H5Oname.c ./src/H5Osdspace.c ./src/H5Oshared.c ./src/H5Ostab.c ./src/H5P.c ./src/H5S.c ./src/H5T.c ./src/H5Tconv.c ./src/H5detect.c ./test/hyperslab.c ./test/istore.c Changed memory allocation functions so they fail instead of dumping core. The `x' was removed from the name to remind us of that: H5MM_xmalloc() -> H5MM_malloc(), etc. H5MM_calloc() takes one argument like H5MM_malloc() instead of two like calloc() because we almost always called it with `1' for one of the arguments anyway. The only difference between the two functions is that H5MM_calloc() returns memory which is initialized to zero. ./src/H5Gent.c ./src/H5Gprivate.h Removed H5G_ent_calloc() since it wasn't used. ./src/H5Fistore.c Fixed a bug found by Albert. Thanks, Albert! This fix combined with the changes to memory allocation prevent the library from failing an assertion if the application uses an unreasonable size for chunks (like Alberts 10000x10000x4). ./src/H5MF.c ./src/H5MFprivate.h Changed H5MF_free() to H5MF_xfree() since calling it with an undefined address is allowed.
Diffstat (limited to 'src/H5HG.c')
-rw-r--r--src/H5HG.c58
1 files changed, 46 insertions, 12 deletions
diff --git a/src/H5HG.c b/src/H5HG.c
index 355e063..f2fe211 100644
--- a/src/H5HG.c
+++ b/src/H5HG.c
@@ -108,13 +108,22 @@ H5HG_create (H5F_t *f, size_t size)
HGOTO_ERROR (H5E_HEAP, H5E_CANTINIT, NULL,
"unable to allocate file space for global heap");
}
- heap = H5MM_xcalloc (1, sizeof(H5HG_heap_t));
+ if (NULL==(heap = H5MM_calloc (sizeof(H5HG_heap_t)))) {
+ HGOTO_ERROR (H5E_RESOURCE, H5E_NOSPACE, NULL,
+ "memory allocation failed");
+ }
heap->addr = addr;
heap->size = size;
heap->dirty = TRUE;
- heap->chunk = H5MM_xmalloc (size);
+ if (NULL==(heap->chunk = H5MM_malloc (size))) {
+ HGOTO_ERROR (H5E_RESOURCE, H5E_NOSPACE, NULL,
+ "memory allocation failed");
+ }
heap->nalloc = H5HG_NOBJS (f, size);
- heap->obj = H5MM_xcalloc (heap->nalloc, sizeof(H5HG_obj_t));
+ if (NULL==(heap->obj = H5MM_calloc (heap->nalloc*sizeof(H5HG_obj_t)))) {
+ HGOTO_ERROR (H5E_RESOURCE, H5E_NOSPACE, NULL,
+ "memory allocation failed");
+ }
/* Initialize the header */
HDmemcpy (heap->chunk, H5HG_MAGIC, H5HG_SIZEOF_MAGIC);
@@ -141,7 +150,11 @@ H5HG_create (H5F_t *f, size_t size)
/* Add this heap to the beginning of the CWFS list */
if (NULL==f->shared->cwfs) {
- f->shared->cwfs = H5MM_xmalloc (H5HG_NCWFS * sizeof(H5HG_heap_t*));
+ f->shared->cwfs = H5MM_malloc (H5HG_NCWFS * sizeof(H5HG_heap_t*));
+ if (NULL==(f->shared->cwfs)) {
+ HGOTO_ERROR (H5E_RESOURCE, H5E_NOSPACE, NULL,
+ "memory allocation failed");
+ }
f->shared->cwfs[0] = heap;
f->shared->ncwfs = 1;
} else {
@@ -187,6 +200,7 @@ H5HG_load (H5F_t *f, const haddr_t *addr, const void __unused__ *udata1,
H5HG_heap_t *ret_value = NULL;
uint8 *p = NULL;
intn i;
+ size_t nalloc;
FUNC_ENTER (H5HG_load, NULL);
@@ -197,9 +211,15 @@ H5HG_load (H5F_t *f, const haddr_t *addr, const void __unused__ *udata1,
assert (!udata2);
/* Read the initial 4k page */
- heap = H5MM_xcalloc (1, sizeof(H5HG_heap_t));
+ if (NULL==(heap = H5MM_calloc (sizeof(H5HG_heap_t)))) {
+ HGOTO_ERROR (H5E_RESOURCE, H5E_NOSPACE, NULL,
+ "memory allocation failed");
+ }
heap->addr = *addr;
- heap->chunk = H5MM_xmalloc (H5HG_MINSIZE);
+ if (NULL==(heap->chunk = H5MM_malloc (H5HG_MINSIZE))) {
+ HGOTO_ERROR (H5E_RESOURCE, H5E_NOSPACE, NULL,
+ "memory allocation failed");
+ }
if (H5F_block_read (f, addr, (hsize_t)H5HG_MINSIZE,
H5D_XFER_DFLT, heap->chunk)<0) {
HGOTO_ERROR (H5E_HEAP, H5E_READERROR, NULL,
@@ -233,7 +253,10 @@ H5HG_load (H5F_t *f, const haddr_t *addr, const void __unused__ *udata1,
if (heap->size > H5HG_MINSIZE) {
haddr_t next_addr = *addr;
H5F_addr_inc (&next_addr, (hsize_t)H5HG_MINSIZE);
- heap->chunk = H5MM_xrealloc (heap->chunk, heap->size);
+ if (NULL==(heap->chunk = H5MM_realloc (heap->chunk, heap->size))) {
+ HGOTO_ERROR (H5E_RESOURCE, H5E_NOSPACE, NULL,
+ "memory allocation failed");
+ }
if (H5F_block_read (f, &next_addr, (hsize_t)(heap->size-H5HG_MINSIZE),
H5D_XFER_DFLT, heap->chunk+H5HG_MINSIZE)<0) {
HGOTO_ERROR (H5E_HEAP, H5E_READERROR, NULL,
@@ -243,8 +266,12 @@ H5HG_load (H5F_t *f, const haddr_t *addr, const void __unused__ *udata1,
/* Decode each object */
p = heap->chunk + H5HG_SIZEOF_HDR (f);
- heap->nalloc = H5HG_NOBJS (f, heap->size);
- heap->obj = H5MM_xcalloc (heap->nalloc, sizeof(H5HG_obj_t));
+ nalloc = H5HG_NOBJS (f, heap->size);
+ if (NULL==(heap->obj = H5MM_calloc (nalloc*sizeof(H5HG_obj_t)))) {
+ HGOTO_ERROR (H5E_RESOURCE, H5E_NOSPACE, NULL,
+ "memory allocation failed");
+ }
+ heap->nalloc = nalloc;
while (p<heap->chunk+heap->size) {
if (p+H5HG_SIZEOF_OBJHDR(f)>heap->chunk+heap->size) {
/*
@@ -276,7 +303,11 @@ H5HG_load (H5F_t *f, const haddr_t *addr, const void __unused__ *udata1,
*/
if (heap->obj[0].size>0) {
if (!f->shared->cwfs) {
- f->shared->cwfs = H5MM_xmalloc (H5HG_NCWFS*sizeof(H5HG_heap_t*));
+ f->shared->cwfs = H5MM_malloc (H5HG_NCWFS*sizeof(H5HG_heap_t*));
+ if (NULL==f->shared->cwfs) {
+ HGOTO_ERROR (H5E_RESOURCE, H5E_NOSPACE, NULL,
+ "memory allocation failed");
+ }
f->shared->ncwfs = 1;
f->shared->cwfs[0] = heap;
} else if (H5HG_NCWFS==f->shared->ncwfs) {
@@ -647,7 +678,10 @@ H5HG_read (H5F_t *f, H5HG_t *hobj, void *object/*out*/)
assert (heap->obj[hobj->idx].begin);
size = heap->obj[hobj->idx].size - H5HG_SIZEOF_OBJHDR (f);
p = heap->obj[hobj->idx].begin + H5HG_SIZEOF_OBJHDR (f);
- if (!object) object = H5MM_xmalloc (size);
+ if (!object && NULL==(object = H5MM_malloc (size))) {
+ HRETURN_ERROR (H5E_RESOURCE, H5E_NOSPACE, NULL,
+ "memory allocation failed");
+ }
HDmemcpy (object, p, size);
/*
@@ -799,7 +833,7 @@ H5HG_remove (H5F_t *f, H5HG_t *hobj)
* to the file free list.
*/
heap->dirty = FALSE;
- H5MF_free (f, &(heap->addr), (hsize_t)(heap->size));
+ H5MF_xfree (f, &(heap->addr), (hsize_t)(heap->size));
H5AC_flush (f, H5AC_GHEAP, &(heap->addr), TRUE);
heap = NULL;
} else {