1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

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
This commit is contained in:
nobu 2018-02-20 04:05:42 +00:00
parent 49f52937bd
commit eb81638530

7
mjit.c
View file

@ -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