php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #25335 Memory Leak with error handler and exceptions
Submitted: 2003-08-31 19:44 UTC Modified: 2010-11-02 17:26 UTC
From: cunha17 at uol dot com dot br Assigned: helly (profile)
Status: Closed Package: Scripting Engine problem
PHP Version: 5CVS-2003-08-31 (dev) OS: *
Private report: No CVE-ID: None
 [2003-08-31 19:44 UTC] cunha17 at uol dot com dot br
Description:
------------
This code below gives some memory leak. The leak only appears when throwing exceptions inside error handler.
The code I'm using is a little more complex 'cause it translates PHP errors into PHP Exceptions, but this piece of code reproduces the leak correctly.


Reproduce code:
---------------
<?
function my_error($nr, $text, $file, $line, $vars)
{
throw new Exception($text);
}

error_reporting(E_ALL);
set_error_handler("my_error");

try {
        include("unexistent");
} catch (Exception $e) {
        echo "EXCEPTION!!!";
}
?>

Expected result:
----------------
EXCEPTION!!!

Actual result:
--------------
EXCEPTION!!!/usr/src/zend2/php-src/Zend/zend.c(914) :  Freeing 0x404C9340 (16 bytes), script=leak.php
=== Total 1 memory leaks detected ===


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2003-09-10 21:49 UTC] cunha17 at uol dot com dot br
Is anyone looking at this ?
 [2003-09-14 15:20 UTC] helly@php.net
For me it seems as if a zval is created after memory manager shutdown. If this is the case we would need to return 'internal zvals' when creating new ones after normal script runtime and also their data must be malloced which is impossible. Or we need to prevent user functions
from beeing called after shutdown_executor() gets called.
 [2003-09-14 15:32 UTC] cunha17 at uol dot com dot br
My knowledge of ZE2 is too limited but I don't think the memory manager got shutdown when the error handler is called (does it?). IMHO it seems the error handler calling mechanism is allocating something and not releasing it since the user function(error handler) is terminated abnormally (exception) and not in the expected way (function end reached, return or exit/die).
 [2003-09-14 15:57 UTC] helly@php.net
The combination of excetions / user space error handling made me think in that direction. Further investigation showed that you were right and there was indeed a problem with temporairy allocated memory.
 [2003-09-14 15:58 UTC] helly@php.net
This bug has been fixed in CVS.

In case this was a PHP problem, snapshots of the sources are packaged
every three hours; this change will be in the next snapshot. You can
grab the snapshot at http://snaps.php.net/.
 
In case this was a documentation problem, the fix will show up soon at
http://www.php.net/manual/.

In case this was a PHP.net website problem, the change will show
up on the PHP.net site and on the mirror sites in short time.
 
Thank you for the report, and for helping us make PHP better.
 [2010-11-02 15:45 UTC] kgrecki at gmail dot com
This still happens on 5.3.2. Was it actually fixed? regression?
 [2010-11-02 17:26 UTC] felipe@php.net
I can't reproduce it.
 [2010-11-02 18:50 UTC] kgrecki at gmail dot com
Sorry, this looked the same issue but actually it can't be replicated with this 
code. I managed to narrow it down and raised a new bug #53228
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Sat Nov 29 15:00:01 2025 UTC