summaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorYukihiro "Matz" Matsumoto <[email protected]>2021-02-26 22:16:07 +0900
committerYukihiro "Matz" Matsumoto <[email protected]>2021-02-26 22:16:07 +0900
commit30b1287df5d2dc23b797a578e4916199715754ef (patch)
tree6ff3a5e97669b65b142dee530fee2dc619909ee0 /src
parent5d371604557c7f0c006334c1383c5f8fe84ae38a (diff)
downloadmruby-30b1287df5d2dc23b797a578e4916199715754ef.tar.gz
mruby-30b1287df5d2dc23b797a578e4916199715754ef.zip
state.c: check irep reference count overflow.
Diffstat (limited to 'src')
-rw-r--r--src/state.c7
1 files changed, 7 insertions, 0 deletions
diff --git a/src/state.c b/src/state.c
index 83cbf1629..d3be618f1 100644
--- a/src/state.c
+++ b/src/state.c
@@ -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++;
}