From 32f6625e3ca183696a5b0e7a2deb632ab43664f0 Mon Sep 17 00:00:00 2001 From: "Su, Tao" Date: Tue, 14 Mar 2023 00:48:03 -0700 Subject: [PATCH 1/2] Fix GH-10755: Memory leak in phar_rename_archive() In phar_renmae_archive() context, added one reference but immediately destroyed another, so do not need to increase refcount. With removal of refcount++ line, PHP/Zend no longer reports memory leak. Updated bug69958.phpt test file accordingly. Testing (PASS on both Debug and Release build) Debug: ./configure --enable-debug Release: ./configure 1) Running selected tests. PASS Phar: bug #69958: Segfault in Phar::convertToData on invalid file [bug69958.phpt] 2) All tests under ext/phar/tests PASSED except skipped. ===================================================================== Number of tests : 530 515 Tests skipped : 15 ( 2.8%) -------- Tests warned : 0 ( 0.0%) ( 0.0%) Tests failed : 0 ( 0.0%) ( 0.0%) Tests passed : 515 ( 97.2%) (100.0%) --------------------------------------------------------------------- Time taken : 26 seconds ===================================================================== Signed-off-by: Su, Tao --- ext/phar/phar_object.c | 3 ++- ext/phar/tests/bug69958.phpt | 2 -- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/ext/phar/phar_object.c b/ext/phar/phar_object.c index ba47cd88439c5..8d29acf50b8ea 100644 --- a/ext/phar/phar_object.c +++ b/ext/phar/phar_object.c @@ -2116,7 +2116,8 @@ static zend_object *phar_rename_archive(phar_archive_data **sphar, char *ext) /* phar_destroy_phar_data(phar); *sphar = NULL; phar = pphar; - phar->refcount++; + /* FIX: GH-10755 Memory leak in phar_rename_archive() */ + /* phar->refcount++; */ newpath = oldpath; goto its_ok; } diff --git a/ext/phar/tests/bug69958.phpt b/ext/phar/tests/bug69958.phpt index b53c76a104951..577b96ce94acb 100644 --- a/ext/phar/tests/bug69958.phpt +++ b/ext/phar/tests/bug69958.phpt @@ -1,7 +1,5 @@ --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 --EXTENSIONS-- phar --FILE-- From d78f7672920946edeee497ec6418b93680046927 Mon Sep 17 00:00:00 2001 From: Tony Su Date: Tue, 14 Mar 2023 21:51:55 +0800 Subject: [PATCH 2/2] Update push.yml --- .github/workflows/push.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/push.yml b/.github/workflows/push.yml index 65cdf72f3caf3..31331522d5452 100644 --- a/.github/workflows/push.yml +++ b/.github/workflows/push.yml @@ -15,6 +15,7 @@ on: - PHP-8.1 - PHP-8.2 - master + - Trigger-branch pull_request: branches: - '**'