-
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
Potential memory leak in addslashes/stripslashes #12508
Comments
For your first code snippet there are no allocations because addslashes and stripslashes will only allocate if the string needs tl change. If it realizes the string stays the same then the refcount of the string is just increased and nothing is allocated. For the second snippet I'm not sure why SPX thinks there is a leak. I don't see one in ASAN or in the ZMM leak detector. Using memory_get_usage also shows no increase. I think therefore the (third party) SPX extension is misreporting or doing something wrong. Possibly getting confused with interned strings? |
Real case is no longer relevant as found that Symfony is collecting some "trace" information (even when --no-debug passed) |
SPX does not directly highlight memory leaks, it only collects memory related metrics at function start/end which can help investigating various memory issues like leaks. Regarding your second example:
As expected,
This is also expected, And finally |
@NoiseByNorthwest latest screenshot was made with following code: <?php
for ($ctr = 0; $ctr < 1_000_000; $ctr++) {
stripslashes(addslashes('\stdClass'));
} no
shouldn't |
Even without |
Description
The following code:
No leak
Resulted in this output:
https://gist.github.com/oleg-andreyev/0cb275e5945061f00560f0fe07a7e068
Potential memory leak
Resulted in this output:
https://gist.github.com/oleg-andreyev/bd85f9441e1b12e603a8592553d6ec69
As you can see (first example):
encode
allocated 0 and free 0decode
allocated 38.1Mb and free 38.1Mbsecond example:
encode
allocated 53.4Mb and free 0decode
allocated 38.1Mb and free 38.1MbPHP Version
8.1.22
Operating System
Alpine Linux v3.18
UPD
same but with extra flag
SPX_BUILTINS=1
it looks like both addslashes/stripslashes are not freeing memory.
The text was updated successfully, but these errors were encountered: