Skip to content

fix: refactor MachO to remove leak - #236

Open
lilfer wants to merge 1 commit into
claration:mainfrom
lilfer:fix-memory-leak
Open

fix: refactor MachO to remove leak#236
lilfer wants to merge 1 commit into
claration:mainfrom
lilfer:fix-memory-leak

Conversation

@lilfer

@lilfer lilfer commented Aug 26, 2026

Copy link
Copy Markdown

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.

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

1 participant