diff --git a/io.c b/io.c index 79e6f16e6..1880c55b5 100644 --- a/io.c +++ b/io.c @@ -2735,6 +2735,9 @@ io_replace_streams(int fd, rb_io_t *dest, rb_io_t *origin) dest->buf = NULL; } dest->buf_offset = origin->buf_offset; + if (origin->path) { + GC_WB(&dest->path, rb_str_dup(origin->path)); + } } static VALUE @@ -2770,10 +2773,6 @@ io_reopen(VALUE io, VALUE nfile) } io_replace_streams(fd, io_s, other); - if (other->path) { - GC_WB(&io_s->path, rb_str_dup(other->path)); - } - *(VALUE *)io = *(VALUE *)nfile; return io;