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 <noreply@anthropic.com>
This commit is contained in:
Yukihiro "Matz" Matsumoto
2026-03-18 23:48:45 +09:00
parent afc0753c1d
commit cb64a0b4a4
+9 -2
View File
@@ -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;