Bug #74565 [NEW]: Uncaught exception causes a memory leak
From: yukiw at simba dot com
Operating system: All
PHP version: Irrelevant
Package: Class/Object related
Bug Type: Bug
Bug description:Uncaught exception causes a memory leak
Description:
------------
When an exception is thrown but uncaught, it causes a memory leak for
the exception object and also op_array zend engine performs
zend_bailout() at php_error_cb().
Running the test in Dr. Memory shows leaks.
Test script:
---------------
<?php
function inverse($x) {
if (!$x) {
throw new Exception('Division by zero.');
}
return 1/$x;
}
echo inverse(5) . "\n";
echo inverse(0) . "\n";
// Continue execution
echo "Hello World\n";
?>
Expected result:
----------------
No leaks should be expected.
Actual result:
--------------
Dr. Memory log:
Error #1: LEAK 128 direct bytes 0x1626e940-0x1626e9c0 + 504 indirect
bytes
# 0 replace_malloc
[d:\drmemory_package\common\alloc_replace.c:2576]
# 1 php7_debug.dll!__zend_malloc
[c:\php-sdk\phpdev\vc14\x86\php-7.1.2-src\zend\zend_alloc.c:2820]
# 2 php7_debug.dll!emalloc
[c:\php-sdk\phpdev\vc14\x86\php-7.1.2-src\zend\zend_alloc.c:2413]
# 3 php7_debug.dll!zend_compile
[c:\php-sdk\phpdev\vc14\x86\php-7.1.2-src\zend\zend_language_scanner.l:591]
# 4 php7_debug.dll!compile_file
[c:\php-sdk\phpdev\vc14\x86\php-7.1.2-src\zend\zend_language_scanner.l:635]
# 5 php7_debug.dll!phar_compile_file
[c:\php-sdk\phpdev\vc14\x86\php-7.1.2-src\ext\phar\phar.c:3320]
# 6 php7_debug.dll!zend_execute_scripts
[c:\php-sdk\phpdev\vc14\x86\php-7.1.2-src\zend\zend.c:1469]
# 7 php7_debug.dll!php_execute_script
[c:\php-sdk\phpdev\vc14\x86\php-7.1.2-src\main\main.c:2537]
# 8 do_cli
[c:\php-sdk\phpdev\vc14\x86\php-7.1.2-src\sapi\cli\php_cli.c:993]
# 9 main
[c:\php-sdk\phpdev\vc14\x86\php-7.1.2-src\sapi\cli\php_cli.c:1381]
Error #2: LEAK 136 direct bytes 0x16270df0-0x16270e78 + 288 indirect
bytes
# 0 replace_malloc
[d:\drmemory_package\common\alloc_replace.c:2576]
# 1 php7_debug.dll!__zend_malloc
[c:\php-sdk\phpdev\vc14\x86\php-7.1.2-src\zend\zend_alloc.c:2820]
# 2 php7_debug.dll!emalloc
[c:\php-sdk\phpdev\vc14\x86\php-7.1.2-src\zend\zend_alloc.c:2413]
# 3 php7_debug.dll!zend_objects_new
[c:\php-sdk\phpdev\vc14\x86\php-7.1.2-src\zend\zend_objects.c:171]
# 4 php7_debug.dll!zend_default_exception_new_ex
[c:\php-sdk\phpdev\vc14\x86\php-7.1.2-src\zend\zend_exceptions.c:210]
# 5 php7_debug.dll!zend_default_exception_new
[c:\php-sdk\phpdev\vc14\x86\php-7.1.2-src\zend\zend_exceptions.c:244]
# 6 php7_debug.dll!_object_and_properties_init
[c:\php-sdk\phpdev\vc14\x86\php-7.1.2-src\zend\zend_api.c:1302]
# 7 php7_debug.dll!_object_init_ex
[c:\php-sdk\phpdev\vc14\x86\php-7.1.2-src\zend\zend_api.c:1310]
# 8 php7_debug.dll!ZEND_NEW_SPEC_CONST_HANDLER
[c:\php-sdk\phpdev\vc14\x86\php-7.1.2-src\zend\zend_vm_execute.h:3217]
# 9 php7_debug.dll!execute_ex
[c:\php-sdk\phpdev\vc14\x86\php-7.1.2-src\zend\zend_vm_execute.h:432]
#10 php7_debug.dll!zend_execute
[c:\php-sdk\phpdev\vc14\x86\php-7.1.2-src\zend\zend_vm_execute.h:474]
#11 php7_debug.dll!zend_execute_scripts
[c:\php-sdk\phpdev\vc14\x86\php-7.1.2-src\zend\zend.c:1475]
--
Edit bug report at https://bugs.php.net/bug.php?id=74565&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=74565&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=74565&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=74565&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=74565&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=74565&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=74565&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=74565&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=74565&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=74565&r=support
Expected behavior: https://bugs.php.net/fix.php?id=74565&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=74565&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=74565&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=74565&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=74565&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=74565&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=74565&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=74565&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=74565&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=74565&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=74565&r=mysqlcfg
Thread (2 messages)
- yukiw at simba dot com