Commit 1df8520e
1df8520ea126Merged
Ori Pekelman <[email protected]> · 5 months ago · 3 files · ~3 modified
Description
Ractor: fix leak-on-exception paths + bounds, per review
Address review findings on the M3 codec/spawn-args:
- sp_Ractor_new_args: if the sp_Ractor calloc fails, free the spawn-arg blob array (ownership had transferred) before raising, instead of leaking it.
- Hash deserialize: the malloc'd key buffer leaked if value-deserialize raised (unshareable tag / truncated message). SPR_STR_HASH now reads the key straight from the reader buffer and roots it (boxed) across the value deser with no malloc; SPR_SYM_HASH interns + frees the key buffer before the value deser, so nothing is live to leak on a longjmp. SPR_STR_HASH also bounds-checks the key length.
- codegen emit_ractor_new: raise a compile-time error when a Ractor.new block has more than 16 parameters (previously the extras were silently dropped and miscompiled as plain locals); emit a NULL-check + sp_oom_die() after the generated spawn-arg-array malloc.
Full suite 930 pass / 0 fail / 0 error; spawn + hash demos valgrind memcheck- and GC-verify-clean.
Co-Authored-By: Claude Opus 4.8 (1M context) [email protected]
Details
- Commit
- 1df8520ea126
- Parent
- 97aa7c3b7787
lib/sp_ractor.cmodifiedView file
@@ -145,7 +145,11 @@
145145
sp_ractor_spawn_arg(). Pass args=NULL, argc=0 for a plain Ractor.new {}. */146146
sp_Ractor *sp_Ractor_new_args(void (*body)(sp_Ractor *), sp_RactorBlob *args, int argc) {147147
sp_Ractor *r = (sp_Ractor *)calloc(1, sizeof(sp_Ractor));148-
if (!r) sp_raise_cls("Ractor::Error", "failed to allocate Ractor");148+
if (!r) {149+
/* Ownership of args transferred to us; free it before unwinding. */150+
if (args) { for (int i = 0; i < argc; i++) free(args[i].data); free(args); }151+
sp_raise_cls("Ractor::Error", "failed to allocate Ractor");152+
}149153
r->body = body;150154
r->spawn_args = args;151155
r->spawn_argc = argc;lib/sp_runtime.hmodifiedView file
Loading diff…
src/codegen.cmodifiedView file
Loading diff…