Skip to content

Commit

Permalink
fix issues of mrb_gc_unregister introduced in 09b1185
Browse files Browse the repository at this point in the history
* fixes partial copy of objects in GC root array (due to missing `* sizeof(mrb_value)`)
* restores the behavior that permitted an unregistered object to be used as an argument
  • Loading branch information
kazuho committed Dec 8, 2016
1 parent 5930a6e commit c2e749f
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions src/gc.c
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,7 @@ mrb_gc_unregister(mrb_state *mrb, mrb_value obj)
mrb_sym root = mrb_intern_lit(mrb, GC_ROOT_NAME);
mrb_value table = mrb_gv_get(mrb, root);
struct RArray *a;
mrb_int i, len;
mrb_int i;

if (mrb_nil_p(table)) return;
if (mrb_type(table) != MRB_TT_ARRAY) {
Expand All @@ -462,14 +462,13 @@ mrb_gc_unregister(mrb_state *mrb, mrb_value obj)
}
a = mrb_ary_ptr(table);
mrb_ary_modify(mrb, a);
len = a->len-1;
for (i=0; i<len; i++) {
for (i = 0; i < a->len; i++) {
if (mrb_obj_eq(mrb, a->ptr[i], obj)) {
memmove(&a->ptr[i], &a->ptr[i+1], len-i);
a->len--;
memmove(&a->ptr[i], &a->ptr[i + 1], (a->len - i) * sizeof(a->ptr[i]));
break;
}
}
a->len--;
}

MRB_API struct RBasic*
Expand Down

0 comments on commit c2e749f

Please sign in to comment.