php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #74565 Uncaught exception causes a memory leak
Submitted: 2017-05-09 19:43 UTC Modified: 2020-12-09 14:45 UTC
From: yukiw at simba dot com Assigned: cmb (profile)
Status: Closed Package: Class/Object related
PHP Version: Irrelevant OS: All
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
19 + 15 = ?
Subscribe to this entry?

 
 [2017-05-09 19:43 UTC] yukiw at simba dot com
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]

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2020-12-09 14:45 UTC] cmb@php.net
-Status: Open +Status: Closed -Assigned To: +Assigned To: cmb
 [2020-12-09 14:45 UTC] cmb@php.net
That should be fixed as of PHP 7.4.0.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Mar 28 23:01:26 2024 UTC