Skip to content

Commit

Permalink
macho: fix all invalid frees
Browse files Browse the repository at this point in the history
  • Loading branch information
kubkon committed Jan 26, 2024
1 parent a9416a1 commit 3ea8d5b
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions src/MachO/Atom.zig
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,18 @@ pub fn getPriority(self: Atom, macho_file: *MachO) u64 {

pub fn getCode(self: Atom, macho_file: *MachO) ![]const u8 {
const gpa = macho_file.base.allocator;
const code = switch (self.getFile(macho_file)) {
switch (self.getFile(macho_file)) {
.dylib => unreachable,
.object => |x| try x.getSectionData(gpa, self.n_sect),
.internal => |x| try gpa.dupe(u8, x.getSectionData(self.n_sect)),
};
return code[self.off..][0..self.size];
.object => |x| {
const code = try x.getSectionData(gpa, self.n_sect);
defer gpa.free(code);
return gpa.dupe(u8, code[self.off..][0..self.size]);
},
.internal => |x| {
const code = x.getSectionData(self.n_sect);
return gpa.dupe(u8, code[self.off..][0..self.size]);
},
}
}

pub fn getRelocs(self: Atom, macho_file: *MachO) []const Relocation {
Expand Down

0 comments on commit 3ea8d5b

Please sign in to comment.