From 885edfef0a0eb1016a906d197399f92375a795e4 Mon Sep 17 00:00:00 2001 From: Stanislav Malyshev Date: Mon, 6 Jul 2015 22:58:28 -0700 Subject: [PATCH] Better fix for bug #69958 --- ext/phar/phar_object.c | 22 +++++++++++++--------- ext/phar/tests/bug69958.phpt | 2 ++ 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/ext/phar/phar_object.c b/ext/phar/phar_object.c index 1184863de9..8cfe0c8228 100644 --- a/ext/phar/phar_object.c +++ b/ext/phar/phar_object.c @@ -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; } } diff --git a/ext/phar/tests/bug69958.phpt b/ext/phar/tests/bug69958.phpt index d63b413c29..96f2198b14 100644 --- a/ext/phar/tests/bug69958.phpt +++ b/ext/phar/tests/bug69958.phpt @@ -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-- --FILE-- -- 2.40.0