summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ext/json/fbuffer/fbuffer.h4
-rw-r--r--ext/json/generator/generator.c1
-rw-r--r--ext/json/generator/generator.h1
3 files changed, 3 insertions, 3 deletions
diff --git a/ext/json/fbuffer/fbuffer.h b/ext/json/fbuffer/fbuffer.h
index 7d1dad7404b..3ff928856d7 100644
--- a/ext/json/fbuffer/fbuffer.h
+++ b/ext/json/fbuffer/fbuffer.h
@@ -92,9 +92,9 @@ static void fbuffer_append_str(FBuffer *fb, VALUE str)
const char *newstr = StringValuePtr(str);
unsigned long len = RSTRING_LEN(str);
- RB_GC_GUARD(str);
-
fbuffer_append(fb, newstr, len);
+
+ RB_GC_GUARD(str);
}
static void fbuffer_append_char(FBuffer *fb, char newchr)
diff --git a/ext/json/generator/generator.c b/ext/json/generator/generator.c
index 6eea7ff1485..21fef2b657f 100644
--- a/ext/json/generator/generator.c
+++ b/ext/json/generator/generator.c
@@ -762,7 +762,6 @@ static void generate_json_bignum(FBuffer *buffer, VALUE Vstate, JSON_Generator_S
{
VALUE tmp = rb_funcall(obj, i_to_s, 0);
fbuffer_append_str(buffer, tmp);
- RB_GC_GUARD(tmp);
}
static void generate_json_float(FBuffer *buffer, VALUE Vstate, JSON_Generator_State *state, VALUE obj)
diff --git a/ext/json/generator/generator.h b/ext/json/generator/generator.h
index 3220178a8f7..4958cf094d4 100644
--- a/ext/json/generator/generator.h
+++ b/ext/json/generator/generator.h
@@ -105,6 +105,7 @@ typedef struct JSON_Generator_StateStruct {
Data_Get_Struct(Vstate, JSON_Generator_State, state); \
buffer = cState_prepare_buffer(Vstate); \
generate_json_##type(buffer, Vstate, state, self); \
+ RB_GC_GUARD(Vstate); \
return fbuffer_to_s(buffer)
static VALUE mHash_to_json(int argc, VALUE *argv, VALUE self);