From 7c8b88a6740c4b1956f5f86febcb1aad9746a693 Mon Sep 17 00:00:00 2001 From: eregon Date: Sat, 13 Jun 2015 20:25:10 +0000 Subject: * io.c (rb_io_s_binread): close fd if seek offset is invalid. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50881 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 4 ++++ io.c | 11 ++++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 311cc43a67..f13e4d9733 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +Sun Jun 14 05:23:51 2015 Benoit Daloze + + * io.c (rb_io_s_binread): close fd if seek offset is invalid. + Sun Jun 14 04:40:32 2015 Benoit Daloze * test/lib/leakchecker.rb (check): refactor. diff --git a/io.c b/io.c index fd8f6f1a97..fcccc71d0a 100644 --- a/io.c +++ b/io.c @@ -9901,7 +9901,16 @@ rb_io_s_binread(int argc, VALUE *argv, VALUE io) arg.argv = argv+1; arg.argc = (argc > 1) ? 1 : 0; if (!NIL_P(offset)) { - rb_io_seek(arg.io, offset, SEEK_SET); + struct seek_arg sarg; + int state = 0; + sarg.io = arg.io; + sarg.offset = offset; + sarg.mode = SEEK_SET; + rb_protect(seek_before_access, (VALUE)&sarg, &state); + if (state) { + rb_io_close(arg.io); + rb_jump_tag(state); + } } return rb_ensure(io_s_read, (VALUE)&arg, rb_io_close, arg.io); } -- cgit v1.2.3