mirror of
https://github.com/mruby/mruby
synced 2026-06-08 16:11:16 +00:00
backtrace.c (pack_backtrace_i): avoid infinite loop; ref #6161
When irep->refcnt reaches UINT16_MAX, mrb_irep_incref() raises exception but the function pack_backtrace_i() is called from mrb_exc_raise() thus causes the infinite loop problem. So this is a hack-ish workaround by making irep reference to NULL if refcnt reaches the maximum count. Probably we will address this issue again to make it better.
This commit is contained in:
+8
-3
@@ -85,10 +85,15 @@ pack_backtrace_i(mrb_state *mrb,
|
||||
struct mrb_backtrace_location **pptr = (struct mrb_backtrace_location**)data;
|
||||
struct mrb_backtrace_location *ptr = *pptr;
|
||||
|
||||
if (loc->irep) {
|
||||
mrb_irep_incref(mrb, (mrb_irep*)loc->irep);
|
||||
}
|
||||
*ptr = *loc;
|
||||
if (ptr->irep) {
|
||||
if (ptr->irep->refcnt == UINT16_MAX) {
|
||||
ptr->irep = NULL;
|
||||
}
|
||||
else {
|
||||
mrb_irep_incref(mrb, (mrb_irep*)ptr->irep);
|
||||
}
|
||||
}
|
||||
*pptr = ptr+1;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user