summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZHIJIE XIE <40601688+dummyx@users.noreply.github.com>2026-03-03 02:40:57 +0900
committerLuke Gruber <luke.gru@gmail.com>2026-03-05 20:57:24 -0500
commit46f51cb3a26e5bfc92251e7971697a9c31bcab44 (patch)
treeda8d29d3a83f21588b4633e2daffd88195cb9966
parent981097a7390db47e06d78b760ed198bff8eb184b (diff)
string.c: guard tmp in rb_str_format_m (GH-16280)
[Bug #21931] Keep tmp alive while RARRAY_CONST_PTR(tmp) is used by rb_str_format. [alan: sunk the guard below usage] Reviewed-by: Alan Wu <XrXr@users.noreply.github.com>
-rw-r--r--string.c4
1 files changed, 3 insertions, 1 deletions
diff --git a/string.c b/string.c
index 5a093ff291..108c21cb16 100644
--- a/string.c
+++ b/string.c
@@ -2557,7 +2557,9 @@ rb_str_format_m(VALUE str, VALUE arg)
VALUE tmp = rb_check_array_type(arg);
if (!NIL_P(tmp)) {
- return rb_str_format(RARRAY_LENINT(tmp), RARRAY_CONST_PTR(tmp), str);
+ VALUE result = rb_str_format(RARRAY_LENINT(tmp), RARRAY_CONST_PTR(tmp), str);
+ RB_GC_GUARD(tmp);
+ return result;
}
return rb_str_format(1, &arg, str);
}