From f8fbd714684120732d39402f4a1311622a3ecd57 Mon Sep 17 00:00:00 2001 From: Jeremy Daer Date: Wed, 5 Aug 2026 08:19:03 -0700 Subject: [PATCH] Mark Result's fieldTypes so the GC can see it mysql2_result_wrapper is xmalloc'd, so every VALUE in it has to be marked by hand. fieldTypes was declared in result.h but never added to rb_mysql_result_mark, so nothing keeps the Array alive. The Array is freed inside the call that allocates it: the fill loop calls rb_mysql_result_fetch_field_type, which allocates Strings and can trigger a GC, and the subsequent rb_ary_store then writes through a freed object slot. No compaction involved -- ordinary GC is enough. Same fix is open upstream as brianmario/mysql2#1454. --- ext/mysql2/result.c | 1 + 1 file changed, 1 insertion(+) diff --git a/ext/mysql2/result.c b/ext/mysql2/result.c index 314cecdaa..8266b30ad 100644 --- a/ext/mysql2/result.c +++ b/ext/mysql2/result.c @@ -62,6 +62,7 @@ static void rb_mysql_result_mark(void * wrapper) { mysql2_result_wrapper * w = wrapper; if (w) { rb_gc_mark(w->fields); + rb_gc_mark(w->fieldTypes); rb_gc_mark(w->rows); rb_gc_mark(w->encoding); rb_gc_mark(w->client);