[php-src] Issue #14373: Memory leak when opcache.file_cache is not set properly
| From: | YuanchengJiang | Date: | Thu, 30 May 2024 12:24:09 +0000 |
| Subject: | [php-src] Issue #14373: Memory leak when opcache.file_cache is not set properly | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-246988@lists.php.net to get a copy of this message | ||
Issue: https://github.com/php/php-src/issues/14373
Author: YuanchengJiang
### Description
The following code:
```php
<?php
class Test {
function method(): object {}
}
class Test2 extends Test {
function method(): X&Y {}
}
?>
```
Resulted in this output:
```
=================================================================
==2133183==ERROR: LeakSanitizer: detected memory leaks
Direct leak of 3040 byte(s) in 95 object(s) allocated from:
#0 0x55c837c88c0e in malloc (/php-src/sapi/cli/php+0x1c88c0e) (BuildId:
ecc3315f95551157854c3640b4c7cb9e07620f31)
#1 0x55c839de3848 in zend_register_functions /php-src/Zend/zend_API.c:3050:19
#2 0x55c839ddc12b in zend_register_module_ex /php-src/Zend/zend_API.c:2568:27
#3 0x55c839de5de9 in zend_register_internal_module /php-src/Zend/zend_API.c:2584:9
#4 0x55c8398fe238 in php_register_extensions /php-src/main/main.c:2009:8
#5 0x55c83acd5024 in php_register_internal_extensions
/php-src/main/internal_functions_cli.c:86:9
#6 0x55c8398fee46 in php_module_startup /php-src/main/main.c:2209:6
#7 0x55c83acdcd88 in php_cli_startup /php-src/sapi/cli/php_cli.c:410:9
#8 0x55c83acd6716 in main /php-src/sapi/cli/php_cli.c:1307:6
#9 0x7f058392bd8f in __libc_start_call_main csu/../sysdeps/nptl/libc_start_call_main.h:58:16
...
Indirect leak of 40 byte(s) in 1 object(s) allocated from:
#0 0x56191b488c0e in malloc (/php-src/sapi/cli/php+0x1c88c0e) (BuildId:
ecc3315f95551157854c3640b4c7cb9e07620f31)
#1 0x56191d5e43be in zend_register_functions /php-src/Zend/zend_API.c:3076:30
#2 0x56191d5f43bf in do_register_internal_class /php-src/Zend/zend_API.c:3402:3
#3 0x56191d5f35c6 in zend_register_internal_class /php-src/Zend/zend_API.c:3466:9
#4 0x56191d5f3578 in zend_register_internal_class_ex /php-src/Zend/zend_API.c:3429:19
#5 0x56191c978051 in register_class_FilesystemIterator
/php-src/ext/spl/spl_directory_arginfo.h:513:16
#6 0x56191c9734bb in zm_startup_spl_directory /php-src/ext/spl/spl_directory.c:2770:30
#7 0x56191c875dbe in zm_startup_spl /php-src/ext/spl/php_spl.c:728:2
#8 0x56191d5d6326 in zend_startup_module_ex /php-src/Zend/zend_API.c:2362:7
#9 0x56191d5db1c1 in zend_startup_module_zval /php-src/Zend/zend_API.c:2377:10
#10 0x56191d683d44 in zend_hash_apply /php-src/Zend/zend_hash.c:2080:13
#11 0x56191d5da41f in zend_startup_modules /php-src/Zend/zend_API.c:2500:2
#12 0x56191d0feef1 in php_module_startup /php-src/main/main.c:2227:2
#13 0x56191e4dcd88 in php_cli_startup /php-src/sapi/cli/php_cli.c:410:9
#14 0x56191e4d6716 in main /php-src/sapi/cli/php_cli.c:1307:6
#15 0x7f375c823d8f in __libc_start_call_main csu/../sysdeps/nptl/libc_start_call_main.h:58:16
SUMMARY: AddressSanitizer: 26184 byte(s) leaked in 818 allocation(s).
```
To reproduce:
```
USE_ZEND_ALLOC=1 /php-src/sapi/cli/php -d "extension_dir=/php-src/modules/" -d
"zend_extension=/php-src/modules/opcache.so" -d "opcache.enable=1" -d
"opcache.enable_cli=1" -d "opcache.file_cache_only=1" -f ./test.php
```
### PHP Version
nightly
### Operating System
ubuntu 22.04