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

ruby-changes:51823

From: k0kubun <ko1@a...>
Date: Wed, 25 Jul 2018 00:40:11 +0900 (JST)
Subject: [ruby-changes:51823] k0kubun:r64037 (trunk): mjit.c: handle memory allocation failure

k0kubun	2018-07-25 00:40:05 +0900 (Wed, 25 Jul 2018)

  New Revision: 64037

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

  Log:
    mjit.c: handle memory allocation failure
    
    which was missing in r64033.
    
    Prior to r64033, memory allocation failure had been checked by
    TRY_WITH_GC and handled by rb_memerror. But calling rb_memerror on MJIT
    worker is problematic since it does EC_JUMP_TAG in the end. Threads
    except Ruby's main thread must not use it.
    
    mjit_compile.c: ditto

  Modified files:
    trunk/mjit.c
    trunk/mjit_compile.c
Index: mjit.c
===================================================================
--- mjit.c	(revision 64036)
+++ mjit.c	(revision 64037)
@@ -334,7 +334,8 @@ form_args(int num, ...) https://github.com/ruby/ruby/blob/trunk/mjit.c#L334
     for (i = len = 0; i < num; i++) {
         args = va_arg(argp, char **);
         n = args_len(args);
-        res = (char **)realloc(res, sizeof(char *) * (len + n + 1));
+        if ((res = (char **)realloc(res, sizeof(char *) * (len + n + 1))) == NULL)
+            return NULL;
         MEMCPY(res + len, args, char *, n + 1);
         len += n;
     }
@@ -767,6 +768,8 @@ compile_c_to_so(const char *c_file, cons https://github.com/ruby/ruby/blob/trunk/mjit.c#L768
 #ifdef _MSC_VER
     solen = strlen(so_file);
     files[0] = p = (char *)malloc(sizeof(char) * (rb_strlen_lit("-Fe") + solen + 1));
+    if (p == NULL)
+        return FALSE;
     p = append_lit(p, "-Fe");
     p = append_str2(p, so_file, solen);
     *p = '\0';
Index: mjit_compile.c
===================================================================
--- mjit_compile.c	(revision 64036)
+++ mjit_compile.c	(revision 64037)
@@ -193,6 +193,8 @@ mjit_compile(FILE *f, const struct rb_is https://github.com/ruby/ruby/blob/trunk/mjit_compile.c#L193
     status.success = TRUE;
     status.local_stack_p = !body->catch_except_p;
     status.stack_size_for_pos = (int *)malloc(sizeof(int) * body->iseq_size);
+    if (status.stack_size_for_pos == NULL)
+        return FALSE;
     memset(status.stack_size_for_pos, NOT_COMPILED_STACK_SIZE, sizeof(int) * body->iseq_size);
 
     /* For performance, we verify stack size only on compilation time (mjit_compile.inc.erb) without --jit-debug */

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

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