[svn-r5925] Purpose:

Code cleanup

Description:
    Eliminate memory leak of compact storage raw data buffer found by purify.

Platforms tested:
    FreeBSD 4.6 (sleipnir) w/C++
    Solaris 2.7 (arabica) w/C++
    IRIX64 6.5 (modi4) w/parallel & FORTRAN
This commit is contained in:
Quincey Koziol 2002-09-13 11:29:30 -05:00
parent f0f56c0c0a
commit 18758623d7
2 changed files with 60 additions and 4 deletions

View File

@ -2184,12 +2184,12 @@ H5D_close(H5D_t *dataset)
free_failed = (H5T_close(dataset->type) < 0 ||
H5I_dec_ref(dataset->dcpl_id) < 0);
/*Update header message of layout for compact dataset.*/
/* Update header message of layout for compact dataset. */
if(dataset->layout.type==H5D_COMPACT && dataset->layout.dirty) {
if(H5O_modify(&(dataset->ent), H5O_LAYOUT, 0, 0, &(dataset->layout))<0)
HRETURN_ERROR(H5E_DATASET, H5E_CANTINIT, FAIL, "unable to update layout message");
dataset->layout.dirty = FALSE;
}
} /* end if */
/* Close the dataset object */
H5O_close(&(dataset->ent));
@ -2201,6 +2201,9 @@ H5D_close(H5D_t *dataset)
* above).
*/
dataset->ent.file = NULL;
/* Free the buffer for the raw data for compact datasets */
if(dataset->layout.type==H5D_COMPACT)
dataset->layout.buf=H5MM_xfree(dataset->layout.buf);
H5FL_FREE(H5D_t,dataset);
if (free_failed)

View File

@ -19,6 +19,7 @@ static void *H5O_layout_decode(H5F_t *f, const uint8_t *p, H5O_shared_t *sh);
static herr_t H5O_layout_encode(H5F_t *f, uint8_t *p, const void *_mesg);
static void *H5O_layout_copy(const void *_mesg, void *_dest);
static size_t H5O_layout_size(H5F_t *f, const void *_mesg);
static herr_t H5O_layout_reset (void *_mesg);
static herr_t H5O_layout_free (void *_mesg);
static herr_t H5O_layout_debug(H5F_t *f, const void *_mesg, FILE * stream,
int indent, int fwidth);
@ -32,7 +33,7 @@ const H5O_class_t H5O_LAYOUT[1] = {{
H5O_layout_encode, /*encode message */
H5O_layout_copy, /*copy the native value */
H5O_layout_size, /*size of message on disk */
NULL, /*reset method */
H5O_layout_reset, /*reset method */
H5O_layout_free, /*free the struct */
NULL, /*get share method */
NULL, /*set share method */
@ -255,6 +256,16 @@ H5O_layout_copy(const void *_mesg, void *_dest)
/* copy */
*dest = *mesg;
/* Deep copy the buffer for compact datasets also */
if(mesg->type==H5D_COMPACT) {
/* Allocate memory for the raw data */
if (NULL==(dest->buf=H5MM_malloc(dest->size)))
HGOTO_ERROR (H5E_RESOURCE, H5E_NOSPACE, NULL, "unable to allocate memory for compact dataset");
/* Copy over the raw data */
HDmemcpy(dest->buf,mesg->buf,dest->size);
} /* end if */
/* Set return value */
ret_value=dest;
@ -348,6 +359,43 @@ done:
FUNC_LEAVE(ret_value);
}
/*-------------------------------------------------------------------------
* Function: H5O_layout_reset
*
* Purpose: Frees resources within a data type message, but doesn't free
* the message itself.
*
* Return: Non-negative on success/Negative on failure
*
* Programmer: Quincey Koziol
* Friday, September 13, 2002
*
* Modifications:
*
*-------------------------------------------------------------------------
*/
static herr_t
H5O_layout_reset (void *_mesg)
{
H5O_layout_t *mesg = (H5O_layout_t *) _mesg;
herr_t ret_value=SUCCEED; /* Return value */
FUNC_ENTER_NOAPI(H5O_layout_reset, FAIL);
if(mesg) {
/* Free the compact storage buffer */
if(mesg->type==H5D_COMPACT)
mesg->buf=H5MM_xfree(mesg->buf);
/* Reset the message */
HDmemset(mesg, 0, sizeof(H5O_layout_t));
} /* end if */
done:
FUNC_LEAVE (ret_value);
}
/*-------------------------------------------------------------------------
* Function: H5O_layout_free
@ -364,14 +412,19 @@ done:
*-------------------------------------------------------------------------
*/
static herr_t
H5O_layout_free (void *mesg)
H5O_layout_free (void *_mesg)
{
H5O_layout_t *mesg = (H5O_layout_t *) _mesg;
herr_t ret_value=SUCCEED; /* Return value */
FUNC_ENTER_NOAPI(H5O_layout_free, FAIL);
assert (mesg);
/* Free the compact storage buffer */
if(mesg->type==H5D_COMPACT)
mesg->buf=H5MM_xfree(mesg->buf);
H5FL_FREE(H5O_layout_t,mesg);
done: