diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2013-10-02 05:19:00 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2013-10-02 05:19:00 +0000 |
commit | a9eca1b20d64a6de125506c299aed51bedf43a73 (patch) | |
tree | 4b7972d0ac8c3fecaa5255096f2304252417eaa1 | |
parent | d60c6c8642e0e6193e5d513135b5dfaaf8a58cfd (diff) | |
download | ruby-a9eca1b20d64a6de125506c299aed51bedf43a73.tar.gz |
io.c: keep fptr read-closed
* io.c (rb_io_close_read): keep fptr in write_io to be discarded, to
fix freed pointer access when it is in use by other threads, and get
rid of potential memory/fd leak.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43112 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r-- | ChangeLog | 6 | ||||
-rw-r--r-- | io.c | 9 |
2 files changed, 12 insertions, 3 deletions
@@ -1,3 +1,9 @@ +Wed Oct 2 14:18:56 2013 Nobuyoshi Nakada <nobu@ruby-lang.org> + + * io.c (rb_io_close_read): keep fptr in write_io to be discarded, to + fix freed pointer access when it is in use by other threads, and get + rid of potential memory/fd leak. + Tue Oct 1 23:44:00 2013 Charlie Somerville <charliesome@ruby-lang.org> * vm_core.h: use __attribute__((unused)) in UNINTIALIZED_VAR on clang @@ -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; } |