Edit report at https://bugs.php.net/bug.php?id=62991&edit=1

 ID:                 62991
 Updated by:         larue...@php.net
 Reported by:        softwareelves at gmail dot com
 Summary:            Segfault with generator and closure.
 Status:             Assigned
 Type:               Bug
 Package:            Reproducible crash
 Operating System:   Mac OSx 10.8.1
 PHP Version:        master-Git-2012-09-02 (Git)
 Assigned To:        nikic
 Block user comment: N
 Private report:     N

 New Comment:

seems the closure has been released after it was executed  while destruct the 
outter scope..


Previous Comments:
------------------------------------------------------------------------
[2012-09-02 01:58:12] softwareelves at gmail dot com

Description:
------------
If you create a generator-closure inside of a function and call that function 
before returning it, it'll cause memory corruption causing a segfault.

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

function test( array $array )
{
        $closure = function() use ( $array ) {
                var_dump( $array );
                yield "hi";
        };
        return $closure(); // if you return the $closure and call it outside 
this function it works.
}

$generator = test( array( 1, 2, 3 ) );
foreach( $generator as $something ) {
        // Segmentation fault: 11
}

Expected result:
----------------
array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) }

Actual result:
--------------
Segmentation fault: 11


------------------------------------------------------------------------



-- 
Edit this bug report at https://bugs.php.net/bug.php?id=62991&edit=1

Reply via email to