From b959263b58e26ef630c085f9f7ddc04373a998c7 Mon Sep 17 00:00:00 2001 From: Peter Zhu Date: Tue, 2 Jan 2024 10:07:14 -0500 Subject: Fix Exception#detailed_message for GC compaction Before this commit, the test fails with RGENGC_CHECK_MODE enabled: TestException#test_detailed_message_under_gc_compact_stress [test/ruby/test_exception.rb:1466]: <"\e[1mfoo (\e[1;4mRuntimeError\e[m\e[1m)\e[m\n" + "\e[1mbar\e[m\n" + "\e[1mbaz\e[m"> expected but was <"\e[1mfoo (\e[1;4mRuntimeError\e[m\e[1m)\e[m\n" + "\e[1m\x00\x00\x00\x00\x00\x00\x00\e[m">. --- eval_error.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'eval_error.c') diff --git a/eval_error.c b/eval_error.c index bdce295f6e..d58df5a737 100644 --- a/eval_error.c +++ b/eval_error.c @@ -125,7 +125,7 @@ print_errinfo(const VALUE eclass, const VALUE errat, const VALUE emesg, const VA } VALUE -rb_decorate_message(const VALUE eclass, const VALUE emesg, int highlight) +rb_decorate_message(const VALUE eclass, VALUE emesg, int highlight) { const char *einfo = ""; long elen = 0; @@ -210,6 +210,8 @@ rb_decorate_message(const VALUE eclass, const VALUE emesg, int highlight) } } + RB_GC_GUARD(emesg); + return str; } -- cgit v1.2.3