]> granicus.if.org Git - php/commitdiff
fix memory leaks. There are some leaks in libz that I can't fix, but none triggered...
authorGreg Beaver <cellog@php.net>
Fri, 8 Feb 2008 04:26:41 +0000 (04:26 +0000)
committerGreg Beaver <cellog@php.net>
Fri, 8 Feb 2008 04:26:41 +0000 (04:26 +0000)
ext/phar/phar.c
ext/phar/tar.c
ext/phar/tests/phar_create_in_cwd.phpt
ext/phar/tests/zf_test.phpt [new file with mode: 0644]
ext/phar/zip.c

index 142f23747aba4a7782798d4f735b7387252c76d5..a0adf9e58f7e24d64b8eff62ee10dc5fe85e712f 100644 (file)
@@ -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);
index 78b0022cde69754690c6cd52b4df691222df823b..999820eb020533711acafbc3d29be7a9c685136d 100644 (file)
@@ -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);
index 4916ecd72633f15eccad9e3fdf6a82c8ea6a6371..a3f8f1d7b1464f34b0da448a14117b3d20064b77 100644 (file)
@@ -32,7 +32,7 @@ __HALT_COMPILER();
 unlink(dirname(__FILE__) . '/brandnewphar.phar');
 ?>
 --EXPECT--
-int(7133)
+int(6591)
 string(200) "<?php
 function __autoload($class)
 {
diff --git a/ext/phar/tests/zf_test.phpt b/ext/phar/tests/zf_test.phpt
new file mode 100644 (file)
index 0000000..67660a4
--- /dev/null
@@ -0,0 +1,34 @@
+--TEST--
+test broken app
+--INI--
+phar.readonly=0
+--FILE--
+<?php
+$file = "zfapp";
+$tgz_file = dirname(__FILE__) . "/$file.tgz";
+chdir(dirname(__FILE__));
+$phar_file = basename(__FILE__, '.php') . '.phar.php';
+@unlink($phar_file);
+copy($tgz_file, $phar_file);
+$a = new Phar($phar_file);
+$a->startBuffering();
+$a->setStub("<?php
+Phar::interceptFileFuncs();
+Phar::webPhar('$file.phar', 'html/index.php');
+echo 'BlogApp is intended to be executed from a web browser\n';
+exit -1;
+__HALT_COMPILER();
+");
+$a->stopBuffering();
+foreach(new RecursiveIteratorIterator($a, RecursiveIteratorIterator::LEAVES_ONLY) as $f) {
+echo $f->getPathName() . "\n";
+}
+?>
+===DONE===
+--CLEAN--
+<?php
+unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.php');
+__HALT_COMPILER();
+?>
+--EXPECT--
+===DONE===
index dc70aa1ee428959356fc51052ddbcb35c462b474..5fc548ebf28063f255b9bfdd9869ef5619044bd3 100644 (file)
@@ -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); \