class.c (copy_class): avoid copying method table in some cases

To prevent memory leaks
This commit is contained in:
Yukihiro "Matz" Matsumoto
2023-05-29 22:57:59 +09:00
parent bba2fd84ea
commit c0c4219b25
+6 -4
View File
@@ -2712,10 +2712,12 @@ copy_class(mrb_state *mrb, mrb_value dst, mrb_value src)
c1->super->flags |= MRB_FL_CLASS_IS_ORIGIN;
}
if (sc->mt) {
dc->mt = mt_copy(mrb, sc->mt);
}
else {
dc->mt = mt_new(mrb);
if (sc->tt == MRB_TT_ICLASS && !(sc->flags & MRB_FL_CLASS_IS_ORIGIN)) {
dc->mt = sc->mt;
}
else {
dc->mt = mt_copy(mrb, sc->mt);
}
}
dc->super = sc->super;
MRB_SET_INSTANCE_TT(dc, MRB_INSTANCE_TT(sc));