summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZHIJIE XIE <40601688+dummyx@users.noreply.github.com>2026-03-03 02:40:57 +0900
committerHiroshi SHIBATA <hsbt@ruby-lang.org>2026-03-04 15:43:44 +0900
commit6cd7b1a1e9e45dd4c43c5cefc421b4c0709cdbd7 (patch)
treef76abb72837815a3bf3bba0cf702bae9804a0876
parentb952b6f099af08a14b57afc0a069597646f3161a (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 d5505fdb1a..500c5d3ed6 100644
--- a/string.c
+++ b/string.c
@@ -2409,7 +2409,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);
}