ruby-changes:60004
From: Nobuyoshi <ko1@a...>
Date: Wed, 12 Feb 2020 12:04:31 +0900 (JST)
Subject: [ruby-changes:60004] 985d1b9ec4 (master): Fixed a potential memory leak
https://git.ruby-lang.org/ruby.git/commit/?id=985d1b9ec4 From 985d1b9ec42e89e39aafadb8ffe68b0b877a7f93 Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada <nobu@r...> Date: Wed, 12 Feb 2020 11:53:51 +0900 Subject: Fixed a potential memory leak `rb_str_new_cstr` can raise a `NoMemoryError`. diff --git a/common.mk b/common.mk index 617d399..a2cc189 100644 --- a/common.mk +++ b/common.mk @@ -3270,6 +3270,7 @@ process.$(OBJEXT): $(hdrdir)/ruby/ruby.h https://github.com/ruby/ruby/blob/trunk/common.mk#L3270 process.$(OBJEXT): $(top_srcdir)/internal/array.h process.$(OBJEXT): $(top_srcdir)/internal/bits.h process.$(OBJEXT): $(top_srcdir)/internal/compilers.h +process.$(OBJEXT): $(top_srcdir)/internal/dir.h process.$(OBJEXT): $(top_srcdir)/internal/error.h process.$(OBJEXT): $(top_srcdir)/internal/eval.h process.$(OBJEXT): $(top_srcdir)/internal/gc.h diff --git a/process.c b/process.c index 51c131e..ec3f5bf 100644 --- a/process.c +++ b/process.c @@ -97,6 +97,7 @@ int initgroups(const char *, rb_gid_t); https://github.com/ruby/ruby/blob/trunk/process.c#L97 #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, https://github.com/ruby/ruby/blob/trunk/process.c#L3494 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"); -- cgit v0.10.2 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/