Bug #62991 [Com]: Segfault with generator and closure.

From: Date: Sun, 02 Sep 2012 09:55:35 +0000
Subject: Bug #62991 [Com]: Segfault with generator and closure.
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-173112@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=62991&edit=1 ID: 62991 Comment by: laruence@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: I got a fix for this. nikic, could you please review this? thanks Previous Comments: ------------------------------------------------------------------------ [2012-09-02 09:54:55] laruence@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] laruence@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

« previous php.bugs (#173112) next »