From ac8bdd20feb53f0fdf2fb766464aed8f6d438376 Mon Sep 17 00:00:00 2001 From: dearblue Date: Sun, 29 Oct 2023 16:53:23 +0900 Subject: [PATCH] Protect strings from GC in `JSON.generate` String objects could be GC'd if `mrb_value_to_string()` was recursively called by an array or hash object. This patch no longer handles GC arena indices, since no other objects are created when strings are dumped. --- src/mrb_json.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/mrb_json.c b/src/mrb_json.c index 4ca51beb..831cd690 100644 --- a/src/mrb_json.c +++ b/src/mrb_json.c @@ -81,7 +81,6 @@ mrb_value_to_string(mrb_state* mrb, mrb_value value, int pretty) { /* FALLTHROUGH */ case MRB_TT_STRING: { - int ai = mrb_gc_arena_save(mrb); char* ptr = RSTRING_PTR(value); char* end = RSTRING_END(value); str = mrb_str_new_cstr(mrb, "\""); @@ -115,7 +114,6 @@ mrb_value_to_string(mrb_state* mrb, mrb_value value, int pretty) { ptr++; } mrb_str_cat_cstr(mrb, str, "\""); - mrb_gc_arena_restore(mrb, ai); } break; case MRB_TT_HASH: