Cut links from `irep` in heaps finalization.
MODIFY
include/mruby/irep.h
include/mruby/irep.h
@@ -58,6 +58,7 @@ MRB_API mrb_value mrb_load_irep_cxt(mrb_state*, const uint8_t*, mrbc_context*);
void mrb_irep_free(mrb_state*, struct mrb_irep*);
void mrb_irep_incref(mrb_state*, struct mrb_irep*);
void mrb_irep_decref(mrb_state*, struct mrb_irep*);
+void mrb_irep_cutref(mrb_state*, struct mrb_irep*);
MRB_END_DECL

MODIFY
src/gc.c
src/gc.c
@@ -817,7 +817,11 @@ obj_free(mrb_state *mrb, struct RBasic *obj, int end)
struct RProc *p = (struct RProc*)obj;
if (!MRB_PROC_CFUNC_P(p) && p->body.irep) {
- mrb_irep_decref(mrb, p->body.irep);
+ mrb_irep *irep = p->body.irep;
+ if (end) {
+ mrb_irep_cutref(mrb, irep);
+ }
+ mrb_irep_decref(mrb, irep);
}
}
break;

MODIFY
src/state.c
src/state.c
@@ -134,6 +134,24 @@ mrb_irep_decref(mrb_state *mrb, mrb_irep *irep)
}
}
+void
+mrb_irep_cutref(mrb_state *mrb, mrb_irep *irep)
+{
+ mrb_irep *tmp;
+ int i;
+
+ for (i=0; i<irep->rlen; i++) {
+ tmp = irep->reps[i];
+ irep->reps[i] = NULL;
+ if (tmp) mrb_irep_decref(mrb, tmp);
+ }
+ if (irep->outer) {
+ tmp = irep->outer;
+ irep->outer = NULL;
+ if (tmp) mrb_irep_decref(mrb, tmp);
+ }
+}
+
void
mrb_irep_free(mrb_state *mrb, mrb_irep *irep)
{
@@ -155,10 +173,13 @@ mrb_irep_free(mrb_state *mrb, mrb_irep *irep)
mrb_free(mrb, irep->pool);
mrb_free(mrb, irep->syms);
for (i=0; i<irep->rlen; i++) {
+ if (irep->reps[i])
mrb_irep_decref(mrb, irep->reps[i]);
}
+ if (irep->outer) {
if (irep->outer)
mrb_irep_decref(mrb, irep->outer);
+ }
mrb_free(mrb, irep->reps);
mrb_free(mrb, irep->lv);
if (irep->own_filename) {

Cut links from `irep` in heaps finalization.