From cb64a0b4a4fb80f9c787803f57e798b1b0463785 Mon Sep 17 00:00:00 2001 From: "Yukihiro \"Matz\" Matsumoto" Date: Wed, 18 Mar 2026 23:48:45 +0900 Subject: [PATCH] symbol.c: use individual malloc for dynamic symbol strings dynamic symbols (created via to_sym, send, etc.) now use mrb_malloc() instead of sym_pool_alloc(). this makes them individually freeable by future symbol GC. static symbols (presym, mrb_intern_static, literals) continue to use the pool allocator for compact storage. Co-authored-by: Claude --- src/symbol.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/symbol.c b/src/symbol.c index c41742287..634c4cd40 100644 --- a/src/symbol.c +++ b/src/symbol.c @@ -341,10 +341,17 @@ sym_intern_common(mrb_state *mrb, const char *name, size_t len, mrb_bool lit) } else { heap_allocation:; - /* Always heap-allocate when not explicitly literal */ uint32_t ulen = (uint32_t)len; size_t ilen = mrb_packed_int_len(ulen); - char *p = sym_pool_alloc(mrb, len+ilen+1); + char *p; + if (lit) { + /* Static symbol from unaligned literal: use pool (not individually freeable) */ + p = sym_pool_alloc(mrb, len+ilen+1); + } + else { + /* Dynamic symbol: use individual malloc (freeable by symbol GC) */ + p = (char*)mrb_malloc(mrb, len+ilen+1); + } mrb_packed_int_encode(ulen, (uint8_t*)p); memcpy(p+ilen, name, len); p[ilen+len] = 0;