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

 ID:                 62991
 Comment 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:

update patch, fix tabs


Previous Comments:
------------------------------------------------------------------------
[2012-09-02 09:58:16] larue...@php.net

The following patch has been added/updated:

Patch Name: bug62991.patch
Revision:   1346579896
URL:        
https://bugs.php.net/patch-display.php?bug=62991&patch=bug62991.patch&revision=1346579896

------------------------------------------------------------------------
[2012-09-02 09:55:35] larue...@php.net

I got a fix for this. nikic, could you please review this? thanks

------------------------------------------------------------------------
[2012-09-02 09:54:55] larue...@php.net

The following patch has been added/updated:

Patch Name: bug62991.patch
Revision:   1346579695
URL:        
https://bugs.php.net/patch-display.php?bug=62991&patch=bug62991.patch&revision=1346579695

------------------------------------------------------------------------
[2012-09-02 08:25:57] larue...@php.net

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

------------------------------------------------------------------------
[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