Skip to content

Commit c44be99

Browse files
mikdusanalexrp
authored andcommitted
debug: fix MemoryAccessor file leak
- patch authored by Jacob Young - tested on alpine-aarch64, 3.21.0, qemu-system 9.2.0 - issue manifested on Alpine Linux aarch64 under qemu-system where zig2 fails during bootstrap: error.ProcessFdQuotaExceeded
1 parent 4de2b1e commit c44be99

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

lib/std/debug.zig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -775,6 +775,7 @@ pub const StackIterator = struct {
775775
}
776776

777777
pub fn deinit(it: *StackIterator) void {
778+
it.ma.deinit();
778779
if (have_ucontext and it.unwind_state != null) it.unwind_state.?.dwarf_context.deinit();
779780
}
780781

lib/std/debug/MemoryAccessor.zig

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,17 @@ pub const init: MemoryAccessor = .{
2525
},
2626
};
2727

28+
pub fn deinit(ma: *MemoryAccessor) void {
29+
switch (native_os) {
30+
.linux => switch (ma.mem.handle) {
31+
-2, -1 => {},
32+
else => ma.mem.close(),
33+
},
34+
else => {},
35+
}
36+
ma.* = undefined;
37+
}
38+
2839
fn read(ma: *MemoryAccessor, address: usize, buf: []u8) bool {
2940
switch (native_os) {
3041
.linux => while (true) switch (ma.mem.handle) {

0 commit comments

Comments
 (0)