Skip to content

Commit cd2eaf2

Browse files
committed
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 git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64037 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
1 parent 461c79f commit cd2eaf2

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

mjit.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,8 @@ form_args(int num, ...)
334334
for (i = len = 0; i < num; i++) {
335335
args = va_arg(argp, char **);
336336
n = args_len(args);
337-
res = (char **)realloc(res, sizeof(char *) * (len + n + 1));
337+
if ((res = (char **)realloc(res, sizeof(char *) * (len + n + 1))) == NULL)
338+
return NULL;
338339
MEMCPY(res + len, args, char *, n + 1);
339340
len += n;
340341
}
@@ -767,6 +768,8 @@ compile_c_to_so(const char *c_file, const char *so_file)
767768
#ifdef _MSC_VER
768769
solen = strlen(so_file);
769770
files[0] = p = (char *)malloc(sizeof(char) * (rb_strlen_lit("-Fe") + solen + 1));
771+
if (p == NULL)
772+
return FALSE;
770773
p = append_lit(p, "-Fe");
771774
p = append_str2(p, so_file, solen);
772775
*p = '\0';

mjit_compile.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,8 @@ mjit_compile(FILE *f, const struct rb_iseq_constant_body *body, const char *func
193193
status.success = TRUE;
194194
status.local_stack_p = !body->catch_except_p;
195195
status.stack_size_for_pos = (int *)malloc(sizeof(int) * body->iseq_size);
196+
if (status.stack_size_for_pos == NULL)
197+
return FALSE;
196198
memset(status.stack_size_for_pos, NOT_COMPILED_STACK_SIZE, sizeof(int) * body->iseq_size);
197199

198200
/* For performance, we verify stack size only on compilation time (mjit_compile.inc.erb) without --jit-debug */

0 commit comments

Comments
 (0)