From d0abcaaa0ffc7f4338ca4102a83472f7f10756f9 Mon Sep 17 00:00:00 2001 From: Quincey Koziol Date: Tue, 10 Jun 2008 12:23:52 -0500 Subject: [svn-r15188] Description: Avoid leaking memory when copying the internal "shared" struct for a named datatype when it's already been opened earlier. Tested on: FreeBSD/32 6.2 (duty) in debug mode FreeBSD/64 6.2 (liberty) w/C++ & FORTRAN, in debug mode Linux/32 2.6 (kagiso) w/PGI compilers, w/C++ & FORTRAN, w/threadsafe, in debug mode Linux/64-amd64 2.6 (smirom) w/default API=1.6.x, w/C++ & FORTRAN, in production mode Linux/64-ia64 2.6 (cobalt) w/Intel compilers, w/C++ & FORTRAN, in production mode Solaris/32 2.10 (linew) w/deprecated symbols disabled, w/C++ & FORTRAN, w/szip filter, in production mode Mac OS X/32 10.5.3 (amazon) in debug mode Linux/64-ia64 2.4 (tg-login3) w/parallel, w/FORTRAN, in production mode --- src/H5T.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/H5T.c b/src/H5T.c index c726e5c..2da5be4 100644 --- a/src/H5T.c +++ b/src/H5T.c @@ -3080,7 +3080,7 @@ H5T_t * H5T_copy(const H5T_t *old_dt, H5T_copy_t method) { H5T_t *new_dt = NULL, *tmp = NULL; - H5T_shared_t *reopened_fo; + H5T_shared_t *reopened_fo = NULL; unsigned i; char *s; H5T_t *ret_value; @@ -3099,10 +3099,6 @@ H5T_copy(const H5T_t *old_dt, H5T_copy_t method) /* Copy shared information (entry information is copied last) */ *(new_dt->shared) = *(old_dt->shared); - /* Copy parent information */ - if(new_dt->shared->parent) - new_dt->shared->parent = H5T_copy(new_dt->shared->parent, method); - /* Check what sort of copy we are making */ switch (method) { case H5T_COPY_TRANSIENT: @@ -3130,7 +3126,7 @@ H5T_copy(const H5T_t *old_dt, H5T_copy_t method) */ if(old_dt->sh_loc.type == H5O_SHARE_TYPE_COMMITTED) { /* Check if the object is already open */ - if((reopened_fo = H5FO_opened(old_dt->sh_loc.file, old_dt->sh_loc.u.loc.oh_addr)) == NULL) { + if(NULL == (reopened_fo = H5FO_opened(old_dt->sh_loc.file, old_dt->sh_loc.u.loc.oh_addr))) { /* Clear any errors from H5FO_opened() */ H5E_clear_stack(NULL); @@ -3174,6 +3170,10 @@ H5T_copy(const H5T_t *old_dt, H5T_copy_t method) break; } /* end switch */ + /* Copy parent information, if we aren't sharing an already opened committed datatype */ + if(NULL == reopened_fo && old_dt->shared->parent) + new_dt->shared->parent = H5T_copy(old_dt->shared->parent, method); + switch(new_dt->shared->type) { case H5T_COMPOUND: { @@ -3537,7 +3537,8 @@ H5T_close(H5T_t *dt) HDassert(dt && dt->shared); - dt->shared->fo_count--; + if(dt->shared->state == H5T_STATE_OPEN) + dt->shared->fo_count--; if(dt->shared->state != H5T_STATE_OPEN || dt->shared->fo_count == 0) { if(H5T_free(dt) < 0) -- cgit v0.12