Re: cvs: php4 /ext/bz2 bz2.c

From: Date: Wed, 12 Jun 2002 19:29:39 +0000
Subject: Re: cvs: php4 /ext/bz2 bz2.c
References: 1  Groups: php.cvs 
Request: Send a blank email to php-cvs+get-12335@lists.php.net to get a copy of this message
> mfischer Tue Jun 11 17:16:23 2002 EDT > > Modified files: > /php4/ext/bz2 bz2.c > Log: > - Fix bzcompress(), remove leaks and add some sanity check on emalloc()s. > you don't need to do emalloc sanity checks, it makes no sense... -Sterling > > Index: php4/ext/bz2/bz2.c > diff -u php4/ext/bz2/bz2.c:1.49 php4/ext/bz2/bz2.c:1.50 > --- php4/ext/bz2/bz2.c:1.49 Fri Apr 19 06:06:41 2002 > +++ php4/ext/bz2/bz2.c Tue Jun 11 17:16:22 2002 > @@ -16,7 +16,7 @@ > +----------------------------------------------------------------------+ > */ > > -/* $Id: bz2.c,v 1.49 2002/04/19 10:06:41 wez Exp $ */ > +/* $Id: bz2.c,v 1.50 2002/06/11 21:16:22 mfischer Exp $ */ > > #ifdef HAVE_CONFIG_H > #include "config.h" > @@ -367,8 +367,7 @@ > block_size = 4, /* Block size for compression algorithm */ > work_factor = 0, /* Work factor for compression algorithm */ > argc; /* Argument count */ > - unsigned int size, /* The size to "realloc" to */ > - source_len, /* Length of the source data */ > + unsigned int source_len, /* Length of the source data */ > dest_len; /* Length of the destination buffer */ > > argc = ZEND_NUM_ARGS(); > @@ -387,7 +386,9 @@ > dest_len = Z_STRLEN_PP(source) + (0.01 * Z_STRLEN_PP(source)) + 600; > > /* Allocate the destination buffer */ > - dest = emalloc(dest_len + 1); > + if (NULL == (dest = emalloc(dest_len + 1))) { > + RETURN_LONG(BZ_MEM_ERROR); > + } > > /* Handle the optional arguments */ > if (argc > 1) { > @@ -401,20 +402,21 @@ > } > > error = BZ2_bzBuffToBuffCompress(dest, > - &size, > + &dest_len, > Z_STRVAL_PP(source), > source_len, > block_size, > 0, > work_factor); > if (error != BZ_OK) { > + efree(dest); > RETURN_LONG(error); > } else { > /* Copy the buffer, we have perhaps allocate alot more than we need, > so we erealloc() the buffer to the proper size */ > - dest = erealloc(dest, size + 1); > - dest[size] = 0; > - RETURN_STRINGL(dest, size, 0); > + dest = erealloc(dest, dest_len + 1); > + dest[dest_len] = 0; > + RETURN_STRINGL(dest, dest_len, 0); > } > } > /* }}} */ > @@ -449,11 +451,9 @@ > /* Depending on the size of the source buffer, either allocate > the length of the source buffer or the a default decompression > size */ > - dest = emalloc( > - PHP_BZ_DECOMPRESS_SIZE > Z_STRLEN_PP(source) ? > - PHP_BZ_DECOMPRESS_SIZE : > - Z_STRLEN_PP(source) > - ); > + if (NULL == (dest = emalloc(PHP_BZ_DECOMPRESS_SIZE > Z_STRLEN_PP(source) ? > PHP_BZ_DECOMPRESS_SIZE : Z_STRLEN_PP(source)))) { > + RETURN_LONG(BZ_MEM_ERROR); > + } > > /* (de)Compression Loop */ > do { > @@ -474,6 +474,7 @@ > } while (error == BZ_OUTBUFF_FULL); > > if (error != BZ_OK) { > + efree(dest); > RETURN_LONG(error); > } else { > /* we might have allocated a little to much, so erealloc the buffer > > > > -- > PHP CVS Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php

« previous php.cvs (#12335) next »