summaryrefslogtreecommitdiff
path: root/io.c
diff options
context:
space:
mode:
Diffstat (limited to 'io.c')
-rw-r--r--io.c9
1 files changed, 6 insertions, 3 deletions
diff --git a/io.c b/io.c
index a60c17a92b..053d34f931 100644
--- a/io.c
+++ b/io.c
@@ -4432,11 +4432,14 @@ rb_io_close_read(VALUE io)
write_io = GetWriteIO(io);
if (io != write_io) {
rb_io_t *wfptr;
- rb_io_fptr_cleanup(fptr, FALSE);
GetOpenFile(write_io, wfptr);
RFILE(io)->fptr = wfptr;
- RFILE(write_io)->fptr = NULL;
- rb_io_fptr_finalize(fptr);
+ /* 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;
}