From 6f4d4bbcc7a510247db7f9c007c00aeb45b563f4 Mon Sep 17 00:00:00 2001 From: "Yukihiro \"Matz\" Matsumoto" Date: Mon, 4 Dec 2017 08:30:20 +0900 Subject: Remove temporary objects from GC arena in `mrb_vformat()'; #3863 --- src/error.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/error.c b/src/error.c index 411a15081..1b24f3065 100644 --- a/src/error.c +++ b/src/error.c @@ -265,6 +265,7 @@ mrb_vformat(mrb_state *mrb, const char *format, va_list ap) const char *p = format; const char *b = p; ptrdiff_t size; + int ai0 = mrb_gc_arena_save(mrb); mrb_value ary = mrb_ary_new_capa(mrb, 4); int ai = mrb_gc_arena_save(mrb); @@ -296,15 +297,20 @@ mrb_vformat(mrb_state *mrb, const char *format, va_list ap) mrb_gc_arena_restore(mrb, ai); } if (b == format) { + mrb_gc_arena_restore(mrb, ai0); return mrb_str_new_cstr(mrb, format); } else { + mrb_value val; + size = p - b; if (size > 0) { mrb_ary_push(mrb, ary, mrb_str_new(mrb, b, size)); - mrb_gc_arena_restore(mrb, ai); } - return mrb_ary_join(mrb, ary, mrb_nil_value()); + val = mrb_ary_join(mrb, ary, mrb_nil_value()); + mrb_gc_arena_restore(mrb, ai0); + mrb_gc_protect(mrb, val); + return val; } } -- cgit v1.2.3