Permalink
Browse files

Fix segfault when send()ing to a closed generator

  • Loading branch information...
1 parent ad525c2 commit 12e928314fb270db31adc361ac4993b4f0fe000a @nikic nikic committed May 29, 2012
Showing with 19 additions and 0 deletions.
  1. +14 −0 Zend/tests/generators/send_after_close.phpt
  2. +5 −0 Zend/zend_generators.c
@@ -0,0 +1,14 @@
+--TEST--
+Calls to send() after close should do nothing
+--FILE--
+<?php
+
+function *gen() { }
+
+$gen = gen();
+$gen->send("Test");
+
+?>
+===DONE===
+--EXPECT--
+===DONE===
View
@@ -308,6 +308,11 @@ ZEND_METHOD(Generator, send)
zend_generator_ensure_initialized(object, generator TSRMLS_CC);
+ /* The generator is already closed, thus can't send anything */
+ if (!generator->execute_data) {
+ return;
+ }
+
/* The sent value was initialized to NULL, so dtor that */
zval_ptr_dtor(generator->send_target->var.ptr_ptr);

0 comments on commit 12e9283

Please sign in to comment.