Bug #74565 [Opn->Csd]: Uncaught exception causes a memory leak

From: Date: Wed, 09 Dec 2020 14:45:40 +0000
Subject: Bug #74565 [Opn->Csd]: Uncaught exception causes a memory leak
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-230957@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=74565&edit=1

 ID:                 74565
 Updated by:         cmb@php.net
 Reported by:        yukiw at simba dot com
 Summary:            Uncaught exception causes a memory leak
-Status:             Open
+Status:             Closed
 Type:               Bug
 Package:            Class/Object related
 Operating System:   All
 PHP Version:        Irrelevant
-Assigned To:        
+Assigned To:        cmb
 Block user comment: N
 Private report:     N

 New Comment:

That should be fixed as of PHP 7.4.0.


Previous Comments:
------------------------------------------------------------------------
[2017-05-09 19:43:53] 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]


------------------------------------------------------------------------



--
Edit this bug report at https://bugs.php.net/bug.php?id=74565&edit=1


Thread (2 messages)

« previous php.bugs (#230957) next »