diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2016-10-10 06:22:30 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2016-10-10 06:22:30 +0000 |
commit | 8c3af8ecc078704128cda961b5316162506e1eb1 (patch) | |
tree | 4f9388417afcdfe816be26a1dafa354128865606 /ruby.c | |
parent | a28d3d591dc6a37cb2544d529a888a99c63e4328 (diff) |
ruby.c: bind fd before waiting
* ruby.c (open_load_file): bind the open fd to an IO instance
before waiting FIFO, not to leak the fd if interrupted.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56388 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ruby.c')
-rw-r--r-- | ruby.c | 24 |
1 files changed, 11 insertions, 13 deletions
@@ -1916,22 +1916,20 @@ open_load_file(VALUE fname_v, int *xflag) #endif e = ruby_is_fd_loadable(fd); - if (e <= 0) { - if (!e) { - e = errno; - (void)close(fd); - rb_load_fail(fname_v, strerror(e)); - } - else { - /* - We need to wait if FIFO is empty. It's FIFO's semantics. - rb_thread_wait_fd() release GVL. So, it's safe. - */ - rb_thread_wait_fd(fd); - } + if (!e) { + e = errno; + (void)close(fd); + rb_load_fail(fname_v, strerror(e)); } f = rb_io_fdopen(fd, mode, fname); + if (e < 0) { + /* + We need to wait if FIFO is empty. It's FIFO's semantics. + rb_thread_wait_fd() release GVL. So, it's safe. + */ + rb_thread_wait_fd(fd); + } } return f; } |