]> granicus.if.org Git - php/commitdiff
Better fix for bug #69958
authorStanislav Malyshev <stas@php.net>
Tue, 7 Jul 2015 05:58:28 +0000 (22:58 -0700)
committerStanislav Malyshev <stas@php.net>
Tue, 7 Jul 2015 16:38:31 +0000 (09:38 -0700)
ext/phar/phar_object.c
ext/phar/tests/bug69958.phpt

index 1184863de9063b10e54018310ef3791173c717b8..8cfe0c82284a5c4dcbb5f2bf520760390f279a0c 100644 (file)
@@ -2089,9 +2089,10 @@ static int phar_copy_file_contents(phar_entry_info *entry, php_stream *fp TSRMLS
 }
 /* }}} */
 
-static zval *phar_rename_archive(phar_archive_data *phar, char *ext, zend_bool compress TSRMLS_DC) /* {{{ */
+static zval *phar_rename_archive(phar_archive_data **sphar, char *ext, zend_bool compress TSRMLS_DC) /* {{{ */
 {
        const char *oldname = NULL;
+       phar_archive_data *phar = *sphar;
        char *oldpath = NULL;
        char *basename = NULL, *basepath = NULL;
        char *newname = NULL, *newpath = NULL;
@@ -2199,6 +2200,7 @@ static zval *phar_rename_archive(phar_archive_data *phar, char *ext, zend_bool c
                                phar->fp = NULL;
                                phar_destroy_phar_data(phar TSRMLS_CC);
                                phar = *pphar;
+                               *sphar = NULL;
                                phar->refcount++;
                                newpath = oldpath;
                                goto its_ok;
@@ -2413,17 +2415,19 @@ no_copy:
                phar_add_virtual_dirs(phar, newentry.filename, newentry.filename_len TSRMLS_CC);
        }
 
-       if ((ret = phar_rename_archive(phar, ext, 0 TSRMLS_CC))) {
+       if ((ret = phar_rename_archive(&phar, ext, 0 TSRMLS_CC))) {
                return ret;
        } else {
-               zend_hash_destroy(&(phar->manifest));
-               zend_hash_destroy(&(phar->mounted_dirs));
-               zend_hash_destroy(&(phar->virtual_dirs));
-               if (phar->fp) {
-                       php_stream_close(phar->fp);
+               if(phar != NULL) {
+                       zend_hash_destroy(&(phar->manifest));
+                       zend_hash_destroy(&(phar->mounted_dirs));
+                       zend_hash_destroy(&(phar->virtual_dirs));
+                       if (phar->fp) {
+                               php_stream_close(phar->fp);
+                       }
+                       efree(phar->fname);
+                       efree(phar);
                }
-               efree(phar->fname);
-               efree(phar);
                return NULL;
        }
 }
index d63b413c29b5ba4f62e7892fd315557d2365905f..96f2198b144fbeea8a369edd5d32ead3e663af71 100644 (file)
@@ -1,5 +1,7 @@
 --TEST--
 Phar: bug #69958: Segfault in Phar::convertToData on invalid file
+--XFAIL--
+Still has memory leaks, see https://bugs.php.net/bug.php?id=70005
 --SKIPIF--
 <?php if (!extension_loaded("phar")) die("skip"); ?>
 --FILE--