diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2017-05-18 11:29:42 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2017-05-18 11:29:42 +0000 |
commit | 92690b62357f99f13acdb4f1639f5e753bb33ed0 (patch) | |
tree | eac737d60bf719ebad4f54dd3b0f3faca9cad8a0 /util.c | |
parent | 97e824136fdadf35f374bd8be0c93675e973cba6 (diff) | |
download | ruby-92690b62357f99f13acdb4f1639f5e753bb33ed0.tar.gz |
potential memory leak
* dir.c (rb_dir_getwd): get rid of potential memory leak.
* util.c (ruby_getcwd): ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58780 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'util.c')
-rw-r--r-- | util.c | 8 |
1 files changed, 8 insertions, 0 deletions
@@ -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 |