diff options
Diffstat (limited to 'io.c')
-rw-r--r-- | io.c | 16 |
1 files changed, 8 insertions, 8 deletions
@@ -4528,7 +4528,8 @@ rb_io_close_read(VALUE io) rb_io_t *fptr; VALUE write_io; - GetOpenFile(io, fptr); + fptr = rb_io_get_fptr(rb_io_taint_check(io)); + if (fptr->fd < 0) return Qnil; if (is_socket(fptr->fd, fptr->pathv)) { #ifndef SHUT_RD # define SHUT_RD 0 @@ -4544,20 +4545,19 @@ rb_io_close_read(VALUE io) write_io = GetWriteIO(io); if (io != write_io) { rb_io_t *wfptr; - GetOpenFile(write_io, wfptr); + wfptr = rb_io_get_fptr(rb_io_taint_check(write_io)); wfptr->pid = fptr->pid; fptr->pid = 0; RFILE(io)->fptr = wfptr; /* bind to write_io temporarily to get rid of memory/fd leak */ fptr->tied_io_for_writing = 0; - fptr->mode &= ~FMODE_DUPLEX; RFILE(write_io)->fptr = fptr; rb_io_fptr_cleanup(fptr, FALSE); /* should not finalize fptr because another thread may be reading it */ return Qnil; } - if (fptr->mode & FMODE_WRITABLE) { + if ((fptr->mode & (FMODE_DUPLEX|FMODE_WRITABLE)) == FMODE_WRITABLE) { rb_raise(rb_eIOError, "closing non-duplex IO for reading"); } return rb_io_close(io); @@ -4589,7 +4589,8 @@ rb_io_close_write(VALUE io) VALUE write_io; write_io = GetWriteIO(io); - GetOpenFile(write_io, fptr); + fptr = rb_io_get_fptr(rb_io_taint_check(write_io)); + if (fptr->fd < 0) return Qnil; if (is_socket(fptr->fd, fptr->pathv)) { #ifndef SHUT_WR # define SHUT_WR 1 @@ -4602,14 +4603,13 @@ rb_io_close_write(VALUE io) return Qnil; } - if (fptr->mode & FMODE_READABLE) { + if ((fptr->mode & (FMODE_DUPLEX|FMODE_READABLE)) == FMODE_READABLE) { rb_raise(rb_eIOError, "closing non-duplex IO for writing"); } if (io != write_io) { - GetOpenFile(io, fptr); + fptr = rb_io_get_fptr(rb_io_taint_check(io)); fptr->tied_io_for_writing = 0; - fptr->mode &= ~FMODE_DUPLEX; } rb_io_close(write_io); return Qnil; |