summaryrefslogtreecommitdiffstats
path: root/src/H5O.c
diff options
context:
space:
mode:
authorRobb Matzke <matzke@llnl.gov>1997-09-02 15:38:26 (GMT)
committerRobb Matzke <matzke@llnl.gov>1997-09-02 15:38:26 (GMT)
commit9d41d3679e1b5d0bb430a7374bb458656e127f15 (patch)
tree2b2a22546f93a839e5b1c9b63e7d36251bb0bb24 /src/H5O.c
parent07dacb9486230fe2522efca266ab06f4558527c3 (diff)
downloadhdf5-9d41d3679e1b5d0bb430a7374bb458656e127f15.zip
hdf5-9d41d3679e1b5d0bb430a7374bb458656e127f15.tar.gz
hdf5-9d41d3679e1b5d0bb430a7374bb458656e127f15.tar.bz2
[svn-r61] ./src/H5.c
Changed atexit() to HDatexit(). ./src/H5AC.c Changed qsort() to HDqsort(). ./src/H5B.c Changed memcmp() to HDmemcmp(). ./src/H5E.c ./src/H5M.c Added parentheses around indirect function calls so that checkposix doesn't complain and to advertise that it's an indirect function call. ./src/H5F.c ./src/H5G.c Added errors field to each function prologue to test the script mentioned above. ./src/H5H.c Changed fputc() to HDfputc(). ./src/H5MM.c ./src/H5MMprivate.h The argument for H5MM_xfree() is a pointer to a constant even though the argument to free() isn't. This reduces the number of warnings in other parts of the code but creates a new warning in this file. ./src/H5O.c Plugged a few memory leaks that happen during error handling. ./src/H5Oname.c ./src/debug.c Added `HD' to the beginning of some posix functions.
Diffstat (limited to 'src/H5O.c')
-rw-r--r--src/H5O.c38
1 files changed, 28 insertions, 10 deletions
diff --git a/src/H5O.c b/src/H5O.c
index 256393c..c4203bc 100644
--- a/src/H5O.c
+++ b/src/H5O.c
@@ -160,12 +160,16 @@ H5O_new (hdf5_file_t *f, intn nlink, size_t size_hint)
*
* Modifications:
*
+ * Robb Matzke, 30 Aug 1997
+ * Plugged memory leaks that occur during error handling.
+ *
*-------------------------------------------------------------------------
*/
static H5O_t *
H5O_load (hdf5_file_t *f, haddr_t addr, const void *_data)
{
H5O_t *oh = NULL;
+ H5O_t *ret_value = (void*)SUCCEED; /*kludge for HGOTO_ERROR*/
uint8 buf[16], *p;
size_t hdr_size, mesg_size;
uintn id;
@@ -173,7 +177,7 @@ H5O_load (hdf5_file_t *f, haddr_t addr, const void *_data)
haddr_t chunk_addr;
size_t chunk_size;
H5O_cont_t *cont=NULL;
-
+
FUNC_ENTER (H5O_load, NULL, NULL);
/* check args */
@@ -187,20 +191,20 @@ H5O_load (hdf5_file_t *f, haddr_t addr, const void *_data)
/* read fixed-lenth part of object header */
hdr_size = H5O_SIZEOF_HDR (f);
if (H5F_block_read (f, addr, hdr_size, buf)<0) {
- HRETURN_ERROR (H5E_OHDR, H5E_READERROR, NULL);
+ HGOTO_ERROR (H5E_OHDR, H5E_READERROR, NULL);
}
p = buf;
/* decode version */
oh->version = *p++;
if (H5O_VERSION!=oh->version) {
- HRETURN_ERROR (H5E_OHDR, H5E_VERSION, NULL);
+ HGOTO_ERROR (H5E_OHDR, H5E_VERSION, NULL);
}
/* decode alignment */
oh->alignment = *p++;
if (4!=oh->alignment) {
- HRETURN_ERROR (H5E_OHDR, H5E_ALIGNMENT, NULL);
+ HGOTO_ERROR (H5E_OHDR, H5E_ALIGNMENT, NULL);
}
/* decode number of messages */
@@ -235,7 +239,7 @@ H5O_load (hdf5_file_t *f, haddr_t addr, const void *_data)
oh->chunk[chunkno].image = H5MM_xmalloc (chunk_size);
if (H5F_block_read (f, chunk_addr, chunk_size,
oh->chunk[chunkno].image)<0) {
- HRETURN_ERROR (H5E_OHDR, H5E_READERROR, NULL);
+ HGOTO_ERROR (H5E_OHDR, H5E_READERROR, NULL);
}
@@ -247,10 +251,10 @@ H5O_load (hdf5_file_t *f, haddr_t addr, const void *_data)
UINT16DECODE (p, mesg_size);
if (id>=NELMTS(message_type_g) || NULL==message_type_g[id]) {
- HRETURN_ERROR (H5E_OHDR, H5E_BADMESG, NULL);
+ HGOTO_ERROR (H5E_OHDR, H5E_BADMESG, NULL);
}
if (p + mesg_size > oh->chunk[chunkno].image + chunk_size) {
- HRETURN_ERROR (H5E_OHDR, H5E_CANTINIT, NULL);
+ HGOTO_ERROR (H5E_OHDR, H5E_CANTINIT, NULL);
}
if (H5O_NULL_ID==id && oh->nmesgs>0 &&
@@ -261,10 +265,10 @@ H5O_load (hdf5_file_t *f, haddr_t addr, const void *_data)
oh->mesg[mesgno].raw_size += 4 + mesg_size;
} else {
/* new message */
- mesgno = oh->nmesgs++;
- if (mesgno>=nmesgs) {
- HRETURN_ERROR (H5E_OHDR, H5E_CANTLOAD, NULL);
+ if (oh->nmesgs>=nmesgs) {
+ HGOTO_ERROR (H5E_OHDR, H5E_CANTLOAD, NULL);
}
+ mesgno = oh->nmesgs++;
oh->mesg[mesgno].type = message_type_g[id];
oh->mesg[mesgno].dirty = FALSE;
oh->mesg[mesgno].native = NULL;
@@ -288,6 +292,20 @@ H5O_load (hdf5_file_t *f, haddr_t addr, const void *_data)
}
}
+done:
+ if (!ret_value && oh) {
+ /*
+ * Free resources.
+ */
+ int i;
+ for (i=0; i<oh->nchunks; i++) {
+ oh->chunk[i].image = H5MM_xfree (oh->chunk[i].image);
+ }
+ oh->chunk = H5MM_xfree (oh->chunk);
+ oh->mesg = H5MM_xfree (oh->mesg);
+ oh = H5MM_xfree (oh);
+ }
+
FUNC_LEAVE (oh);
}