From ede01c24766def69e0740b5e19e7b48789cbded8 Mon Sep 17 00:00:00 2001 From: Zoffix Znet Date: Fri, 27 Jan 2017 14:09:33 +0000 Subject: [PATCH] Fix crash in .pull-one on IO::Handle.lines iterator That seems to occur with RI::Batch/RI::Rotor iterators or when .pull-one is called manually. The iterator calls .get() on the Handle that reads from its $!PIO and when that's exhaused the $!PIO is set to null. So when the next .pull-one is done, we try to .get() on a closed handle by attempting to read from nqp::null() that $!PIO is now is. Bug find: https://irclog.perlgeek.de/perl6-dev/2017-01-27#i_13996365 --- src/core/IO/Handle.pm | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/core/IO/Handle.pm b/src/core/IO/Handle.pm index e6d41b5ac33..576700c3a02 100644 --- a/src/core/IO/Handle.pm +++ b/src/core/IO/Handle.pm @@ -565,11 +565,15 @@ my class IO::Handle does IO { nqp::create(self)!SET-SELF(handle, close); } method pull-one() is raw { - nqp::if(nqp::defined(my \g = $!handle.get), - g, - nqp::stmts( - nqp::if($!close, $!handle.close), - IterationEnd)) + nqp::if( + nqp::isnull( + nqp::getattr(nqp::decont($!handle), $!handle.WHAT, '$!PIO')), + IterationEnd, + nqp::if(nqp::defined(my \g = $!handle.get), + g, + nqp::stmts( + nqp::if($!close, $!handle.close), + IterationEnd))) } method push-all($target --> IterationEnd) { my $line;