Skip to content

Commit

Permalink
check ttype before object allocation; fix #3294
Browse files Browse the repository at this point in the history
  • Loading branch information
matz committed Nov 29, 2016
1 parent 27d166d commit 630733f
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/gc.c
Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,17 @@ mrb_obj_alloc(mrb_state *mrb, enum mrb_vtype ttype, struct RClass *cls)
static const RVALUE RVALUE_zero = { { { MRB_TT_FALSE } } };
mrb_gc *gc = &mrb->gc;

if (cls) {
enum mrb_vtype tt = MRB_INSTANCE_TT(cls);
if (tt != MRB_TT_FALSE &&
ttype != MRB_TT_SCLASS &&
ttype != MRB_TT_ICLASS &&
ttype != MRB_TT_ENV &&
ttype != tt) {
mrb_raisef(mrb, E_TYPE_ERROR, "allocation failure of %S", mrb_obj_value(cls));
}
}

#ifdef MRB_GC_STRESS
mrb_full_gc(mrb);
#endif
Expand Down

0 comments on commit 630733f

Please sign in to comment.