Skip to content

Fix memory leak: action_system palette shortcut strings#94

Closed
meszmate wants to merge 1 commit intomainfrom
fix/action-system-shortcut-leak
Closed

Fix memory leak: action_system palette shortcut strings#94
meszmate wants to merge 1 commit intomainfrom
fix/action-system-shortcut-leak

Conversation

@meszmate
Copy link
Copy Markdown
Owner

Summary

The leak fix from PR #93's branch landed too late — the merge happened before the second commit was pushed, so the leak fix never reached main. This PR re-applies it cleanly against main.

The leak

Each action with a binding had its shortcut string allocated via `ActionRegistry.formatKey(persistent, ...)` and passed to `CommandPalette` by reference. The palette stores `Command` structs verbatim — it never owns or frees the shortcut bytes — so on program exit the gpa reported one `memory address … leaked` entry per registered action with a binding.

Fix

Add a `palette_shortcuts: ArrayList([]u8)` field on the `Model` that owns the formatted strings:

  • Each `formatKey` result is appended into it
  • The palette borrows the slice (no ownership change)
  • `Model.deinit` frees every element and the list itself

This keeps the palette API simple (it stays a borrow-only consumer) while ensuring the example cleans up properly.

Test plan

  • `zig build` passes
  • `zig build test` — full suite passes
  • `./zig-out/bin/action_system` then `q` — exits with zero `memory address … leaked` reports

Each action's binding was formatted into a heap string with
ActionRegistry.formatKey and handed to CommandPalette by reference.
The palette stores Command structs verbatim — it never owns or frees
the shortcut bytes — so the strings leaked at program exit (gpa
reported one leak per registered action with a binding).

Add a palette_shortcuts: ArrayList([]u8) field on Model that owns the
formatted strings. Push each formatKey result into it, hand the slice
to the palette by reference, and free everything in deinit.

Verified: action_system now exits with zero gpa leak reports.
@meszmate
Copy link
Copy Markdown
Owner Author

Superseded by #95 — fixes the leak at the library level (CommandPalette now owns its command strings) instead of working around it in the example.

@meszmate meszmate closed this Apr 24, 2026
@meszmate meszmate deleted the fix/action-system-shortcut-leak branch April 24, 2026 13:38
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