Skip to content

fix: heap-allocate map/set structs to prevent class field segfaults#318

Merged
cs01 merged 1 commit intomainfrom
fix-collection-heap-alloc
Mar 13, 2026
Merged

fix: heap-allocate map/set structs to prevent class field segfaults#318
cs01 merged 1 commit intomainfrom
fix-collection-heap-alloc

Conversation

@cs01
Copy link
Copy Markdown
Owner

@cs01 cs01 commented Mar 13, 2026

Summary

  • Map/Set/StringMap/StringSet variable declarations used stack allocation (alloca) for the collection struct. When stored in class fields, the stack frame is freed after the constructor returns, leaving a dangling pointer — causing segfaults on later access.
  • Changed all 5 collection allocation sites in variable-allocator.ts to use GC_malloc (heap allocation), matching the pattern already used by the literal generators in map.ts and set.ts.

Test plan

  • New test fixture maps/map-class-field.ts — Map stored in class field, accessed after construction
  • npm run verify:quick passes (tests + self-hosting Stage 1)

🤖 Generated with Claude Code

@cs01 cs01 merged commit 2e2ef01 into main Mar 13, 2026
12 checks passed
@cs01 cs01 deleted the fix-collection-heap-alloc branch March 13, 2026 04:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant