[前][次][番号順一覧][スレッド一覧]

ruby-changes:50374

From: nobu <ko1@a...>
Date: Tue, 20 Feb 2018 13:05:48 +0900 (JST)
Subject: [ruby-changes:50374] nobu:r62490 (trunk): mjit.c: fix memory leak

nobu	2018-02-20 13:05:42 +0900 (Tue, 20 Feb 2018)

  New Revision: 62490

  https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=62490

  Log:
    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.

  Modified files:
    trunk/mjit.c
Index: mjit.c
===================================================================
--- mjit.c	(revision 62489)
+++ mjit.c	(revision 62490)
@@ -1227,8 +1227,11 @@ system_tmpdir(void) https://github.com/ruby/ruby/blob/trunk/mjit.c#L1227
     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

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]