Skip to content

Commit

Permalink
Fixed bug #72684 (AppendIterator segfault with closed generator)
Browse files Browse the repository at this point in the history
  • Loading branch information
adoy committed Jul 27, 2016
1 parent 24d8f6e commit 4c2e1a1
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
2 changes: 1 addition & 1 deletion ext/spl/spl_iterators.c
Original file line number Diff line number Diff line change
Expand Up @@ -1688,7 +1688,7 @@ static inline void spl_dual_it_rewind(spl_dual_it_object *intern TSRMLS_DC)
{
spl_dual_it_free(intern TSRMLS_CC);
intern->current.pos = 0;
if (intern->inner.iterator->funcs->rewind) {
if (intern->inner.iterator && intern->inner.iterator->funcs->rewind) {
intern->inner.iterator->funcs->rewind(intern->inner.iterator TSRMLS_CC);
}
}
Expand Down
21 changes: 21 additions & 0 deletions ext/spl/tests/bug72684.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
--TEST--
Bug #72684 (AppendIterator segfault with closed generator)
--FILE--
<?php

function createGenerator() { yield 1; }
$generator = createGenerator();

$appendIterator = new AppendIterator();
$appendIterator->append($generator);

iterator_to_array($appendIterator);
try {
iterator_to_array($appendIterator);
} catch (\Exception $e) {
echo $e->getMessage();
}

?>
--EXPECT--
Cannot traverse an already closed generator

0 comments on commit 4c2e1a1

Please sign in to comment.