diff options
| author | Yukihiro "Matz" Matsumoto <[email protected]> | 2017-12-04 08:30:20 +0900 |
|---|---|---|
| committer | Yukihiro "Matz" Matsumoto <[email protected]> | 2017-12-04 08:56:11 +0900 |
| commit | 6f4d4bbcc7a510247db7f9c007c00aeb45b563f4 (patch) | |
| tree | e1a13a65d62ff44a0943fe8f261801c8ca16b40a | |
| parent | 5d04e3316bc96c0df6084c0bf6020e3038837ad3 (diff) | |
| download | mruby-6f4d4bbcc7a510247db7f9c007c00aeb45b563f4.tar.gz mruby-6f4d4bbcc7a510247db7f9c007c00aeb45b563f4.zip | |
Remove temporary objects from GC arena in `mrb_vformat()'; #3863
| -rw-r--r-- | src/error.c | 10 |
1 files changed, 8 insertions, 2 deletions
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; } } |
