From: Greg Beaver Date: Fri, 8 Feb 2008 04:26:41 +0000 (+0000) Subject: fix memory leaks. There are some leaks in libz that I can't fix, but none triggered... X-Git-Tag: RELEASE_2_0_0a1~570 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=e3c64bd53b35725e25149861e9a3cee65e1117cf;p=php fix memory leaks. There are some leaks in libz that I can't fix, but none triggered in the current tests --- diff --git a/ext/phar/phar.c b/ext/phar/phar.c index 142f23747a..a0adf9e58f 100644 --- a/ext/phar/phar.c +++ b/ext/phar/phar.c @@ -1014,7 +1014,6 @@ int phar_create_or_parse_filename(char *fname, int fname_len, char *alias, int a return SUCCESS; } else { /* file exists, but is either corrupt or not a phar archive */ - php_stream_close(fp); if (actual) { efree(actual); } @@ -1199,6 +1198,7 @@ static int phar_open_fp(php_stream* fp, char *fname, int fname_len, char *alias, if (!phar_has_zlib) { MAPPHAR_ALLOC_FAIL("unable to decompress gzipped phar archive \"%s\" to temporary file, enable zlib extension in php.ini") } + INIT_ZVAL(filterparams); array_init(&filterparams); /* this is defined in zlib's zconf.h */ #ifndef MAX_WBITS @@ -1220,7 +1220,6 @@ static int phar_open_fp(php_stream* fp, char *fname, int fname_len, char *alias, MAPPHAR_ALLOC_FAIL("unable to decompress gzipped phar archive \"%s\", ext/zlib is buggy in PHP versions older than 5.2.6") } } - zval_dtor(&filterparams); php_stream_filter_append(&temp->writefilters, filter); if (0 == php_stream_copy_to_stream(fp, temp, PHP_STREAM_COPY_ALL)) { if (err) { @@ -2407,10 +2406,10 @@ int phar_flush(phar_archive_data *phar, char *user_stub, long len, char **error /* to properly compress, we have to tell zlib to add a zlib header */ zval filterparams; + INIT_ZVAL(filterparams); array_init(&filterparams); add_assoc_long(&filterparams, "window", MAX_WBITS+16); filter = php_stream_filter_create("zlib.deflate", &filterparams, php_stream_is_persistent(phar->fp) TSRMLS_CC); - zval_dtor(&filterparams); if (!filter) { if (error) { spprintf(error, 4096, "unable to compress all contents of phar \"%s\" using zlib, PHP versions older than 5.2.6 have a buggy zlib", phar->fname); diff --git a/ext/phar/tar.c b/ext/phar/tar.c index 78b0022cde..999820eb02 100644 --- a/ext/phar/tar.c +++ b/ext/phar/tar.c @@ -607,7 +607,6 @@ int phar_tar_flush(phar_archive_data *phar, char *user_stub, long len, char **er #endif add_assoc_long(&filterparams, "window", MAX_WBITS + 16); filter = php_stream_filter_create("zlib.deflate", &filterparams, php_stream_is_persistent(phar->fp) TSRMLS_CC); - zval_dtor(&filterparams); if (!filter) { /* copy contents uncompressed rather than lose them */ php_stream_copy_to_stream(newfile, phar->fp, PHP_STREAM_COPY_ALL); diff --git a/ext/phar/tests/phar_create_in_cwd.phpt b/ext/phar/tests/phar_create_in_cwd.phpt index 4916ecd726..a3f8f1d7b1 100644 --- a/ext/phar/tests/phar_create_in_cwd.phpt +++ b/ext/phar/tests/phar_create_in_cwd.phpt @@ -32,7 +32,7 @@ __HALT_COMPILER(); unlink(dirname(__FILE__) . '/brandnewphar.phar'); ?> --EXPECT-- -int(7133) +int(6591) string(200) "startBuffering(); +$a->setStub("stopBuffering(); +foreach(new RecursiveIteratorIterator($a, RecursiveIteratorIterator::LEAVES_ONLY) as $f) { +echo $f->getPathName() . "\n"; +} +?> +===DONE=== +--CLEAN-- + +--EXPECT-- +===DONE=== diff --git a/ext/phar/zip.c b/ext/phar/zip.c index dc70aa1ee4..5fc548ebf2 100644 --- a/ext/phar/zip.c +++ b/ext/phar/zip.c @@ -213,6 +213,7 @@ foundit: entry.fp_type = PHAR_FP; #define PHAR_ZIP_FAIL(errmsg) \ zend_hash_destroy(&mydata->manifest); \ + mydata->manifest.arBuckets = 0; \ php_stream_close(fp); \ if (mydata->metadata) { \ zval_dtor(mydata->metadata); \