Skip to content

fix(core): refactor MachO to remove leak - #236

Merged
claration merged 1 commit into
claration:mainfrom
lilfer:fix-memory-leak
Sep 19, 2026
Merged

claration merged 1 commit into
claration:mainfrom
lilfer:fix-memory-leak

Conversation

@lilfer

@lilfer lilfer commented Aug 26, 2026

Copy link
Copy Markdown
Contributor

Fixes #115

Resolves a memory leak caused by using Box::leak in Mach-O manipulation routines.

Problem

  • MachO can't both own both MachFile and the binary buffer it borrows without self-referencing, so the previous implementation leaked the buffer to satisfy the 'static lifetime.
  • Methods in MachOExt called self.data = Box::leak(...) each time binary load commands were modified.

This caused memory accumulation over time when performing repeated signing operations.

Changes

  • Changed MachO to store data: Vec<u8> instead of MachFile<'static>, dynamically parsing MachFile<'_> on demand in macho_file(&self).
  • Updated MachOExt methods to return the modified data instead of mutating and leaking it.
  • Added a modify_binaries helper in MachO to apply closures and update self.data. Since every edit already wrote to disk, I removed write_changes and merged it into this helper, but with this setup it should be easy to instead chain edits before saving.

@claration claration changed the title fix: refactor MachO to remove leak fix(core): refactor MachO to remove leak Sep 19, 2026
@claration
claration merged commit 0d9353e into claration:main Sep 19, 2026
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.

[Bug] Very high ram usage on macOS

2 participants