mirror of
https://github.com/anomalyco/opentui.git
synced 2026-04-25 21:15:52 +03:00
[PR #430] [CLOSED] fix(core): fix memory leaks in Zig unicode encoding and grapheme pool #1316
Labels
No labels
bug
core
documentation
feature
good first issue
help wanted
pull-request
question
react
solid
tmux
windows
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/opentui#1316
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/anomalyco/opentui/pull/430
Author: @edlsh
Created: 12/19/2025
Status: ❌ Closed
Base:
main← Head:fix/zig-critical-bugs📝 Commits (4)
c3b22bdfix(core): wrap kitty graphics query in tmux DCS passthrough933f322fix(core): defer kitty graphics query until detection4a9aa5emove test script to core/dev8f11e06fix(core): fix memory leaks in Zig unicode encoding and grapheme pool📊 Changes
8 files changed (+176 additions, -12 deletions)
View changed files
➕
packages/core/dev/test-tmux-graphics-334.sh(+68 -0)📝
packages/core/docs/env-vars.md(+14 -0)📝
packages/core/src/zig.ts(+6 -0)📝
packages/core/src/zig/ansi.zig(+2 -0)📝
packages/core/src/zig/grapheme.zig(+4 -0)📝
packages/core/src/zig/lib.zig(+26 -1)📝
packages/core/src/zig/renderer.zig(+9 -0)📝
packages/core/src/zig/terminal.zig(+47 -11)📄 Description
Summary
Fixes critical memory leaks in the Zig native code for unicode encoding and grapheme pool operations.
Changes
1. Fix
errdeferthat never runs inencodeUnicode(lib.zig)Problem: The function returns
bool, buterrdeferonly triggers on error union returns. All failure paths usedcatch return false, which is a normal return—not an error return—so cleanup never executed.Fix: Replace
errdeferwithdefer+ success flag pattern:var success = false;at starterrdefertodefer { if (!success) { ... } }success = true;before finalreturn true;2. Fix grapheme leak on realloc failure (lib.zig)
Problem: After
pool.alloc()+pool.incref(), ifreallocfails, the newly allocated grapheme wasn't tracked yet in the result array, so it would leak.Fix: Track pending grapheme with
var pending_gid: ?u32 = null;:pending_gid = gidimmediately after allocationpending_gid = nullafter successfully stored in result arraypending_gidif set3. Add bounds checks in GraphemePool (grapheme.zig)
Problem:
incref,decref,get, andgetRefcountdidn't validateclass_idbefore array access.Fix: Added
if (class_id >= MAX_CLASSES) return GraphemePoolError.InvalidId;to all four methods.Testing
bun run buildpasses (all 6 platform binaries)bun run test:nativepasses (1241/1242 tests, 1 skipped)🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.