diff options
author | Nobuyoshi Nakada <nobu@ruby-lang.org> | 2020-02-12 11:53:51 +0900 |
---|---|---|
committer | Nobuyoshi Nakada <nobu@ruby-lang.org> | 2020-02-12 11:58:56 +0900 |
commit | 985d1b9ec42e89e39aafadb8ffe68b0b877a7f93 (patch) | |
tree | 40dd2c6dc338ae04892577175be70aa705eb3dc3 /process.c | |
parent | 155ab9caa6bbdeae2377bd9c18f11fc83d938217 (diff) |
Fixed a potential memory leak
`rb_str_new_cstr` can raise a `NoMemoryError`.
Diffstat (limited to 'process.c')
-rw-r--r-- | process.c | 5 |
1 files changed, 2 insertions, 3 deletions
@@ -97,6 +97,7 @@ int initgroups(const char *, rb_gid_t); #include "hrtime.h" #include "internal.h" #include "internal/bits.h" +#include "internal/dir.h" #include "internal/error.h" #include "internal/eval.h" #include "internal/hash.h" @@ -3493,10 +3494,8 @@ rb_execarg_run_options(const struct rb_execarg *eargp, struct rb_execarg *sargp, if (eargp->chdir_given) { if (sargp) { - char *cwd = ruby_getcwd(); sargp->chdir_given = 1; - sargp->chdir_dir = hide_obj(rb_str_new2(cwd)); - xfree(cwd); + sargp->chdir_dir = hide_obj(rb_dir_getwd_ospath()); } if (chdir(RSTRING_PTR(eargp->chdir_dir)) == -1) { /* async-signal-safe */ ERRMSG("chdir"); |