From cba7dd0ddde3711058ae3854ece47928aaa0235d Mon Sep 17 00:00:00 2001 From: Quincey Koziol Date: Tue, 2 Oct 2007 09:55:35 -0500 Subject: [svn-r14170] Description: Avoid memory leak when realloc() fails during attempt to get larger buffer as we are decompressing deflated data. Tested on: FreeBSD/32 6.2 (duty) Linux/32 2.6 (kagiso) --- src/H5Zdeflate.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/H5Zdeflate.c b/src/H5Zdeflate.c index 3c3678c..56b910b 100644 --- a/src/H5Zdeflate.c +++ b/src/H5Zdeflate.c @@ -118,18 +118,21 @@ H5Z_filter_deflate (unsigned flags, size_t cd_nelmts, } else { /* If we're not done and just ran out of buffer space, get more */ - if (0==z_strm.avail_out) { + if(0 == z_strm.avail_out) { + void *new_outbuf; /* Pointer to new output buffer */ + /* Allocate a buffer twice as big */ nalloc *= 2; - if (NULL==(outbuf = H5MM_realloc(outbuf, nalloc))) { + if(NULL == (new_outbuf = H5MM_realloc(outbuf, nalloc))) { (void)inflateEnd(&z_strm); HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, 0, "memory allocation failed for deflate uncompression") - } + } /* end if */ + outbuf = new_outbuf; /* Update pointers to buffer for next set of uncompressed data */ z_strm.next_out = (unsigned char*)outbuf + z_strm.total_out; z_strm.avail_out = (uInt)(nalloc - z_strm.total_out); - } + } /* end if */ } /* end else */ } while(status==Z_OK); -- cgit v0.12