-
Notifications
You must be signed in to change notification settings - Fork 7.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix GH-10755: Memory leak in phar_rename_archive() #10848
Conversation
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 <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for your interest in fixing this issue!
Since this is a bugfix, you need to target the lowest supported bugfix branch. In this case this is PHP-8.1.
The failures you're seeing in CI on Windows platforms is because the test exception message uses a forward slash (/) in the pathname, while on Windows a backwards slash () is used. You can fix that by replacing all occurrences under --EXPECTF--
of "%s/bug69958.tar"
with "%sbug69958.tar"
in the test file.
Finally, the failure you're seeing on ASAN can probably be reproduced locally if you configure with ./configure --enable-debug --enable-address-sanitizer
. The error message likely means that the code allocates something using malloc, but frees using efree instead of free. So that allocation should probably changed to emalloc instead of malloc. i.e. malloc & free must be paired, and emalloc and efree must be paired, they must not be mixed.
You can probably try to figure out the origin of the problem by using GDB.
@nielsdos Thanks for the detailed explanation and comments, which is essentially helpful for me. I will follow them and continue digging ... |
@nielsdos A question for you to clarify |
Yes.
We will merge your work into PHP-8.1 and then merge the commits upwards into 8.2 and master. So we will always make sure it gets to all branches that need the fix. In short, all you have to do is target the 8.1 version and we will make sure it gets to all versions. |
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
Running selected tests.
PASS Phar: bug #69958: Segfault in Phar::convertToData on invalid file [bug69958.phpt]
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