mirror of
https://github.com/mruby/mruby
synced 2026-06-08 16:11:16 +00:00
449040400a
The mrb_match_data struct stores `source` and `regexp` as plain mrb_value members of a C-allocated struct, which the GC does not scan. Under MRB_GC_STRESS the source string could be collected while the MatchData was still alive, causing md[0] to read freed memory (observed as "\xff\xff\xff"). Also stash source and regexp as instance variables on the MatchData object so they remain reachable via the object's iv_tbl during GC. The C struct members continue to provide fast direct access, and no other call sites need to change. Co-authored-by: Claude <noreply@anthropic.com>