1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

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
This commit is contained in:
nobu 2018-02-07 07:48:24 +00:00
parent c5e114528b
commit 039db0d2fa

9
mjit.c
View file

@ -87,6 +87,9 @@
#include <winsock2.h> #include <winsock2.h>
#include <windows.h> #include <windows.h>
#else #else
#ifdef HAVE_FCNTL_H
#include <fcntl.h>
#endif
#include <sys/wait.h> #include <sys/wait.h>
#include <sys/time.h> #include <sys/time.h>
#include <dlfcn.h> #include <dlfcn.h>
@ -323,9 +326,7 @@ start_process(const char *path, char *const *argv)
#else #else
{ {
/* Not calling IO functions between fork and exec for safety */ /* Not calling IO functions between fork and exec for safety */
FILE *f = fopen(ruby_null_device, "w"); int dev_null = rb_cloexec_open(ruby_null_device, O_WRONLY, 0);
int dev_null = fileno(f);
fclose(f);
if ((pid = vfork()) == 0) { if ((pid = vfork()) == 0) {
if (mjit_opts.verbose == 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, STDERR_FILENO);
dup2(dev_null, STDOUT_FILENO); dup2(dev_null, STDOUT_FILENO);
} }
(void)close(dev_null);
pid = execvp(path, argv); /* Pid will be negative on an error */ pid = execvp(path, argv); /* Pid will be negative on an error */
/* Even if we successfully found CC to compile PCH we still can /* Even if we successfully found CC to compile PCH we still can
fail with loading the CC in very rare cases for some reasons. 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); verbose(1, "MJIT: Error in execvp: %s\n", path);
_exit(1); _exit(1);
} }
(void)close(dev_null);
} }
#endif #endif
return pid; return pid;