-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Closed
Labels
Description
Description
The following code:
No leak
<?php
function encode() {
return addslashes('stdClass');
}
function decode(string $str) {
return stripslashes($str);
}
for ($ctr = 0; $ctr < 1_000_000; $ctr++) {
$php = encode();
decode($php);
}
Resulted in this output:
https://gist.github.com/oleg-andreyev/0cb275e5945061f00560f0fe07a7e068
Potential memory leak
function encode() {
return addslashes('\stdClass');
}
function decode(string $str) {
return stripslashes($str);
}
for ($ctr = 0; $ctr < 1_000_000; $ctr++) {
$php = encode();
decode($php);
}
Resulted in this output:
https://gist.github.com/oleg-andreyev/bd85f9441e1b12e603a8592553d6ec69
As you can see (first example):
encode
allocated 0 and free 0
decode
allocated 38.1Mb and free 38.1Mb
second example:
encode
allocated 53.4Mb and free 0
decode
allocated 38.1Mb and free 38.1Mb
PHP 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.