php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #74606 Segfault within try/catch/finally nesting in Generators
Submitted: 2017-05-17 17:52 UTC Modified: -
From: bwoebi@php.net Assigned:
Status: Closed Package: Reproducible crash
PHP Version: 7.1Git-2017-05-17 (Git) OS: Irrelevant
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 you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: bwoebi@php.net
New email:
PHP Version: OS:

 

 [2017-05-17 17:52 UTC] bwoebi@php.net
Description:
------------
Nesting a try/finally inside a try/catch in a loop within a Generator will cause too many live vars to be cleaned up (i.e. outside its live range).

Test script:
---------------
function gen() {
        $array = ["foo"];
        $array[] = "bar";

        foreach ($array as $item) {
                try {
                        try {
                                yield;
                        } finally {
                                echo "fin $item\n";
                        }
                } catch (\Exception $e) {
                        echo "catch\n";
                        continue;
                }
        }
}
$g = gen();
$g->throw(new Exception);

Expected result:
----------------
fin foo
catch
fin bar


Actual result:
--------------
fin foo
catch
fin bar
<segmentation fault>

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2017-05-17 17:59 UTC] bwoebi@php.net
Automatic comment on behalf of bobwei9@hotmail.com
Revision: http://git.php.net/?p=php-src.git;a=commit;h=649494c0ee54102ac4a6c62fd5faf38143efb107
Log: Fixed bug #74606 (Segfault within try/catch/finally nesting in Generators)
 [2017-05-17 17:59 UTC] bwoebi@php.net
-Status: Open +Status: Closed
 [2017-05-17 17:59 UTC] bwoebi@php.net
Automatic comment on behalf of bobwei9@hotmail.com
Revision: http://git.php.net/?p=php-src.git;a=commit;h=649494c0ee54102ac4a6c62fd5faf38143efb107
Log: Fixed bug #74606 (Segfault within try/catch/finally nesting in Generators)
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Thu Jul 03 06:01:34 2025 UTC