Commit 36fbf774
36fbf7742bc6Merged
Yukihiro "Matz" Matsumoto <[email protected]> · 5 months ago · 1 file · ~1 modified
Description
Root the proc capture struct during closure construction
The proc capture struct (_capv_N = sp_gc_alloc(...)) was populated and handed to sp_proc_new_meta without a GC root. sp_proc_new_meta itself allocates the proc box, and that allocation can fire a collection that sweeps the still-unreferenced capture struct; the later .call then dereferences a freed pointer (segfault under allocation pressure). Emit SP_GC_ROOT for the capture struct right after it is allocated.
Refs #1393.
Co-Authored-By: Claude Opus 4.8 (1M context) [email protected]
Details
- Commit
- 36fbf7742bc6
- Parent
- f4ff48f4c210
src/codegen.cmodifiedView file
@@ -1007,6 +1007,11 @@
10071007
if (g_pre) {10081008
emit_indent(g_pre, g_indent);10091009
buf_printf(g_pre, "_proc_cap_%d *_capv_%d = (_proc_cap_%d *)sp_gc_alloc(sizeof(_proc_cap_%d), NULL, _proc_cap_scan_%d);\n", pid, pid, pid, pid, pid);1010+
/* Root the capture struct: sp_proc_new_meta allocates the proc box and1011+
can fire a GC that would otherwise sweep this still-unreferenced1012+
struct before the box adopts it. */1013+
emit_indent(g_pre, g_indent);1014+
buf_printf(g_pre, "SP_GC_ROOT(_capv_%d);\n", pid);10101015
for (int i = 0; i < ncap; i++) { emit_indent(g_pre, g_indent); buf_printf(g_pre, "_capv_%d->%s = _cell_%s;\n", pid, caps.v[i], caps.v[i]); }10111016
}10121017
buf_printf(b, "sp_proc_new_meta((void *)_proc_%d, _capv_%d, _proc_cap_scan_%d, %d, %s, %d, %s)",