summaryrefslogtreecommitdiff
path: root/dir.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-05-18 11:29:42 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-05-18 11:29:42 +0000
commit92690b62357f99f13acdb4f1639f5e753bb33ed0 (patch)
treeeac737d60bf719ebad4f54dd3b0f3faca9cad8a0 /dir.c
parent97e824136fdadf35f374bd8be0c93675e973cba6 (diff)
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 'dir.c')
-rw-r--r--dir.c6
1 files changed, 6 insertions, 0 deletions
diff --git a/dir.c b/dir.c
index 50a8b18..7ab4654 100644
--- a/dir.c
+++ b/dir.c
@@ -1054,9 +1054,14 @@ rb_dir_getwd(void)
VALUE cwd;
rb_encoding *fs = rb_filesystem_encoding();
int fsenc = rb_enc_to_index(fs);
+ VALUE path_guard;
+#undef RUBY_UNTYPED_DATA_WARNING
+#define RUBY_UNTYPED_DATA_WARNING 0
if (fsenc == ENCINDEX_US_ASCII) fsenc = ENCINDEX_ASCII;
+ path_guard = Data_Wrap_Struct((VALUE)0, NULL, RUBY_DEFAULT_FREE, NULL);
path = my_getcwd();
+ DATA_PTR(path_guard) = path;
#ifdef _WIN32
cwd = rb_str_conv_enc(rb_utf8_str_new_cstr(path), NULL, fs);
#else
@@ -1068,6 +1073,7 @@ rb_dir_getwd(void)
#endif
rb_enc_associate_index(cwd, fsenc);
#endif
+ DATA_PTR(path_guard) = 0;
xfree(path);
return cwd;