php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #77575 set_error_handler() / ErrorException memory leak
Submitted: 2019-02-06 02:55 UTC Modified: -
Votes:1
Avg. Score:3.0 ± 0.0
Reproduced:0 of 0 (0.0%)
From: frame86 at live dot com Assigned:
Status: Open Package: *General Issues
PHP Version: 7.2.14 OS: Ubuntu 18.04.1 LTS
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: frame86 at live dot com
New email:
PHP Version: OS:

 

 [2019-02-06 02:55 UTC] frame86 at live dot com
Description:
------------
Using an error handler, throwing and catching the ErrorException leaks memory.

Test script:
---------------
<?php

$last = time();
ini_set('memory_limit', '8G');

set_error_handler(function ($severity, $message, $file, $line) {
	throw new \ErrorException($message, 0, $severity, $file, $line);
});

while(true)
{
	try {
		trigger_error("Something");
	} catch(\Throwable $e) {
		
	}
	
	if(time() - $last >= 1) {
		$last = time();
		printf("\nMemory: %.4f", memory_get_usage() / (1024 * 1024));
	}

        gc_collect_cycles(); // doesn't help much
}

Expected result:
----------------
Nearly constant memory usage

Actual result:
--------------
Memory: 3.7187
Memory: 5.0504
Memory: 6.0593
Memory: 6.9050
Memory: 7.6437
Memory: 8.3095
Memory: 8.9218
Memory: 9.4904
...
Memory: 97.7963
Memory: 219.5202
Memory: 300.1706
Segmentation fault (core dumped)


Patches

Add a Patch

Pull Requests

Add a Pull Request

 
PHP Copyright © 2001-2019 The PHP Group
All rights reserved.
Last updated: Sat Feb 23 00:01:25 2019 UTC