Skip to content

fix: use memory index for cabi_realloc$N export suffix#63

Merged
avrabe merged 1 commit intomainfrom
fix/cabi-realloc-memory-index
Mar 22, 2026
Merged

fix: use memory index for cabi_realloc$N export suffix#63
avrabe merged 1 commit intomainfrom
fix/cabi-realloc-memory-index

Conversation

@avrabe
Copy link
Contributor

@avrabe avrabe commented Mar 22, 2026

Summary

The merger exported cabi_realloc$N using component index as suffix, but the P2
wrapper looks them up by memory index. When component indices are non-consecutive
after flattening (e.g., 0, 3, 5), the naming mismatch caused all components to
fall back to component 0's allocator — cross-memory heap corruption.

Fix: use memory_index_map to get the merged memory index and use that as suffix.

Test plan

  • All 78 tests pass
  • clippy clean
  • resources, xcrate, ownership, package_with_version all pass

🤖 Generated with Claude Code

The merger exported cabi_realloc$N using the component index as suffix,
but the P2 wrapper looks them up by memory index. When component indices
are non-consecutive after flattening (e.g., 0, 3, 5), the naming
mismatch caused all components to fall back to component 0's allocator,
leading to cross-memory heap corruption.

Fix: use merged.memory_index_map to get the memory index for the
component's first memory, and use that as the export suffix.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@avrabe avrabe merged commit 03f9833 into main Mar 22, 2026
@avrabe avrabe deleted the fix/cabi-realloc-memory-index branch March 22, 2026 13:57
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