php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #34065 throw in foreach causes memory leaks
Submitted: 2005-08-10 12:06 UTC Modified: 2006-09-19 21:44 UTC
Votes:10
Avg. Score:4.5 ± 0.7
Reproduced:7 of 9 (77.8%)
Same Version:3 (42.9%)
Same OS:5 (71.4%)
From: dmitry@php.net Assigned: dmitry
Status: Closed Package: Scripting Engine problem
PHP Version: 6CVS, 5CVS (2005-08-23) OS: *
Private report: No CVE-ID:
 [2005-08-10 12:06 UTC] dmitry@php.net
Description:
------------
Throwing exception from inside a foreach block can produce memory leaks, because ZEND_SWITCH_FREE opcode is not executed.

Reproduce code:
---------------
<?php
$data = file(__FILE__);
try {
  foreach ($data as $line) {
    throw new Exception("error");
  }
} catch (Exception $e) {
  echo "ok\n";
}
?>


Expected result:
----------------
ok

Actual result:
--------------
memory leaks

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-08-28 09:20 UTC] dmitry@php.net
See also bug #38623
 [2006-09-19 21:44 UTC] dmitry@php.net
Fixed in CVS HEAD and PHP_5_2.
 
PHP Copyright © 2001-2014 The PHP Group
All rights reserved.
Last updated: Thu Apr 17 06:02:13 2014 UTC