From 2368dbdfa3c438b614a4727bde7cacac2d0a87a9 Mon Sep 17 00:00:00 2001 From: nagachika Date: Fri, 16 Mar 2018 17:34:44 +0000 Subject: merge revision(s) 58745,58780,59040,60743: [Backport #13863] rb_w32_ugetcwd: UTF-8 version getcwd * dir.c (rb_dir_getwd): convert from UTF-8. * win32/win32.c (w32_getcwd): codepage aware getcwd using GetCurrentDirectoryW. potential memory leak * dir.c (rb_dir_getwd): get rid of potential memory leak. * util.c (ruby_getcwd): ditto. file.c: realpath in OS path encoding * dir.c (rb_dir_getwd_ospath): return cwd path in the OS path encoding. * file.c (rb_realpath_internal): work in the OS path encoding load.c: cwd encoding * load.c (rb_get_expanded_load_path): save cwd cache in OS path encoding, to get rid of unnecessary conversion and infinite loading when it needs encoding conversion. [ruby-dev:50221] [Bug #13863] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_4@62784 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- util.c | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'util.c') diff --git a/util.c b/util.c index 0934996984..3ebb2fea9a 100644 --- a/util.c +++ b/util.c @@ -511,7 +511,10 @@ ruby_getcwd(void) char *buf = xmalloc(2); strcpy(buf, "."); #elif defined HAVE_GETCWD +# undef RUBY_UNTYPED_DATA_WARNING +# define RUBY_UNTYPED_DATA_WARNING 0 # if defined NO_GETCWD_MALLOC + VALUE guard = Data_Wrap_Struct((VALUE)0, NULL, RUBY_DEFAULT_FREE, NULL); int size = 200; char *buf = xmalloc(size); @@ -519,17 +522,22 @@ ruby_getcwd(void) int e = errno; if (e != ERANGE) { xfree(buf); + DATA_PTR(guard) = NULL; rb_syserr_fail(e, "getcwd"); } size *= 2; + DATA_PTR(guard) = buf; buf = xrealloc(buf, size); } # else + VALUE guard = Data_Wrap_Struct((VALUE)0, NULL, free, NULL); char *buf, *cwd = getcwd(NULL, 0); + DATA_PTR(guard) = cwd; if (!cwd) rb_sys_fail("getcwd"); buf = ruby_strdup(cwd); /* allocate by xmalloc */ free(cwd); # endif + DATA_PTR(RB_GC_GUARD(guard)) = NULL; #else # ifndef PATH_MAX # define PATH_MAX 8192 -- cgit v1.2.3