state.c: check irep reference count overflow.

This commit is contained in:
Yukihiro "Matz" Matsumoto
2021-02-26 22:16:07 +09:00
parent 5d37160455
commit 30b1287df5
+7
View File
@@ -4,6 +4,7 @@
** See Copyright Notice in mruby.h
*/
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <mruby.h>
@@ -110,6 +111,12 @@ void
mrb_irep_incref(mrb_state *mrb, mrb_irep *irep)
{
if (irep->flags & MRB_IREP_NO_FREE) return;
if (irep->refcnt == UINT16_MAX) {
mrb_garbage_collect(mrb);
if (irep->refcnt == UINT16_MAX) {
mrb_raise(mrb, E_RUNTIME_ERROR, "too many irep references");
}
}
irep->refcnt++;
}