diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2018-02-07 07:48:24 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2018-02-07 07:48:24 +0000 |
commit | 039db0d2faa067a46b0b10dc0f04dc144879ecc7 (patch) | |
tree | 360c2950d7235b436679e9365de6465532c87209 /mjit.c | |
parent | c5e114528bf9ad1a57c6ba895e499c539b75fe42 (diff) | |
download | ruby-039db0d2faa067a46b0b10dc0f04dc144879ecc7.tar.gz |
mjit.c: fd is no longer valid after fclose
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62278 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'mjit.c')
-rw-r--r-- | mjit.c | 9 |
1 files changed, 6 insertions, 3 deletions
@@ -87,6 +87,9 @@ #include <winsock2.h> #include <windows.h> #else +#ifdef HAVE_FCNTL_H +#include <fcntl.h> +#endif #include <sys/wait.h> #include <sys/time.h> #include <dlfcn.h> @@ -323,9 +326,7 @@ start_process(const char *path, char *const *argv) #else { /* Not calling IO functions between fork and exec for safety */ - FILE *f = fopen(ruby_null_device, "w"); - int dev_null = fileno(f); - fclose(f); + int dev_null = rb_cloexec_open(ruby_null_device, O_WRONLY, 0); if ((pid = vfork()) == 0) { if (mjit_opts.verbose == 0) { @@ -335,6 +336,7 @@ start_process(const char *path, char *const *argv) dup2(dev_null, STDERR_FILENO); dup2(dev_null, STDOUT_FILENO); } + (void)close(dev_null); pid = execvp(path, argv); /* Pid will be negative on an error */ /* Even if we successfully found CC to compile PCH we still can fail with loading the CC in very rare cases for some reasons. @@ -342,6 +344,7 @@ start_process(const char *path, char *const *argv) verbose(1, "MJIT: Error in execvp: %s\n", path); _exit(1); } + (void)close(dev_null); } #endif return pid; |