Merge pull request #954 from carsonmcdonald/arrcrashfix

Add null check after mrb_realloc for array
This commit is contained in:
Yukihiro "Matz" Matsumoto
2013-03-05 21:59:43 -08:00
+7 -1
View File
@@ -192,8 +192,14 @@ ary_expand_capa(mrb_state *mrb, struct RArray *a, mrb_int len)
if (capa > ARY_MAX_SIZE) capa = ARY_MAX_SIZE; /* len <= capa <= ARY_MAX_SIZE */
if (capa > a->aux.capa) {
mrb_value *expanded_ptr = (mrb_value *)mrb_realloc(mrb, a->ptr, sizeof(mrb_value)*capa);
if(!expanded_ptr) {
mrb_raise(mrb, E_RUNTIME_ERROR, "out of memory");
}
a->aux.capa = capa;
a->ptr = (mrb_value *)mrb_realloc(mrb, a->ptr, sizeof(mrb_value)*capa);
a->ptr = expanded_ptr;
}
}