aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--string.c2
-rw-r--r--test/ruby/test_string.rb11
2 files changed, 13 insertions, 0 deletions
diff --git a/string.c b/string.c
index 8af608047a..9da5708964 100644
--- a/string.c
+++ b/string.c
@@ -7231,6 +7231,8 @@ str_undump(VALUE str)
}
}
+ RB_GC_GUARD(str);
+
return undumped;
invalid_format:
rb_raise(rb_eRuntimeError, "invalid dumped string; not wrapped with '\"' nor '\"...\".force_encoding(\"...\")' form");
diff --git a/test/ruby/test_string.rb b/test/ruby/test_string.rb
index 2ccabcbe80..42553cba82 100644
--- a/test/ruby/test_string.rb
+++ b/test/ruby/test_string.rb
@@ -896,6 +896,17 @@ CODE
}
end
+ def test_undump_gc_compact_stress
+ a = S("Test") << 1 << 2 << 3 << 9 << 13 << 10
+ EnvUtil.under_gc_compact_stress do
+ assert_equal(a, S('"Test\\x01\\x02\\x03\\t\\r\\n"').undump)
+ end
+
+ EnvUtil.under_gc_compact_stress do
+ assert_equal(S("\u{ABCDE 10ABCD}"), S('"\\u{ABCDE 10ABCD}"').undump)
+ end
+ end
+
def test_dup
for frozen in [ false, true ]
a = S("hello")