summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-02-20 04:05:42 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-02-20 04:05:42 +0000
commiteb816385307abc0da39274728473e972f91cc833 (patch)
treea43b53c13e4b4724c70605b8df8d8b977ad05374
parent49f52937bd9461a677123a16a011c7bc261900a4 (diff)
downloadruby-eb816385307abc0da39274728473e972f91cc833.tar.gz
mjit.c: fix memory leak
* mjit.c (system_tmpdir): rb_w32_wstr_to_mbstr returns the pointer to `malloc`ed region. allocate with `xmalloc` instead. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62490 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--mjit.c7
1 files changed, 5 insertions, 2 deletions
diff --git a/mjit.c b/mjit.c
index acd4ea3d27..6f186c03b7 100644
--- a/mjit.c
+++ b/mjit.c
@@ -1227,8 +1227,11 @@ system_tmpdir(void)
WCHAR tmppath[_MAX_PATH];
UINT len = rb_w32_system_tmpdir(tmppath, numberof(tmppath));
if (len) {
- tmpdir = rb_w32_wstr_to_mbstr(CP_UTF8, tmppath, -1, NULL);
- return get_string(tmpdir);
+ int blen = WideCharToMultiByte(CP_UTF8, 0, tmppath, len, NULL, 0, NULL, NULL);
+ tmpdir= xmalloc(blen + 1);
+ WideCharToMultiByte(CP_UTF8, 0, tmppath, len, tmpdir, blen, NULL, NULL);
+ tmpdir[blen] = '\0';
+ return tmpdir;
}
#elif defined _CS_DARWIN_USER_TEMP_DIR
#ifndef MAXPATHLEN