Skip to content

fix: zero-initialize WASM page buffers to prevent memory corruption#142

Open
sauyon wants to merge 1 commit intocoder:mainfrom
sauyon:sauyon/fix-mem-free
Open

fix: zero-initialize WASM page buffers to prevent memory corruption#142
sauyon wants to merge 1 commit intocoder:mainfrom
sauyon:sauyon/fix-mem-free

Conversation

@sauyon
Copy link

@sauyon sauyon commented Mar 22, 2026

PageList only zeroed page buffers in debug/safe builds, relying on the OS to guarantee zeroed memory in release builds. On WASM there is no OS guarantee — the allocator reuses freed memory as-is. This caused two bugs:

  1. Stale cell data from freed terminals appearing in newly created ones
  2. WASM memory corruption after freeing terminals that processed multi-codepoint grapheme clusters (flag emoji, skin tones, ZWJ sequences), crashing all subsequent terminal writes

The fix makes @Memset(page_buf, 0) unconditional on WASM in both initPages and createPageExt.

Includes two previously-failing regression tests. Should resolve #141.

…oder#141)

PageList only zeroed page buffers in debug/safe builds, relying on the
OS to guarantee zeroed memory in release builds. On WASM there is no OS
guarantee — the allocator reuses freed memory as-is. This caused two bugs:

1. Stale cell data from freed terminals appearing in newly created ones
2. WASM memory corruption after freeing terminals that processed
   multi-codepoint grapheme clusters (flag emoji, skin tones, ZWJ
   sequences), crashing all subsequent terminal writes

The fix makes @Memset(page_buf, 0) unconditional on WASM in both
initPages and createPageExt.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
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.

WASM memory corruption after freeing terminal that processed multi-codepoint grapheme clusters

1 participant