|  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
Avg. Score:4.5 ± 0.7
Reproduced:7 of 9 (77.8%)
Same Version:3 (42.9%)
Same OS:5 (71.4%)
From: Assigned: dmitry (profile)
Status: Closed Package: Scripting Engine problem
PHP Version: 6CVS, 5CVS (2005-08-23) OS: *
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Bug Type:
New email:
PHP Version: OS:


 [2005-08-10 12:06 UTC]
Throwing exception from inside a foreach block can produce memory leaks, because ZEND_SWITCH_FREE opcode is not executed.

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

Expected result:

Actual result:
memory leaks


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2006-08-28 09:20 UTC]
See also bug #38623
 [2006-09-19 21:44 UTC]
Fixed in CVS HEAD and PHP_5_2.
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Jun 23 04:01:29 2024 UTC