authorgravatar for michael.dusan@gmail.comMichael Dusan <michael.dusan@gmail.com> 2025-01-30 09:27:32-05:00
committergravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2025-02-01 04:27:24+01:00
logc44be99f1abff2ab67d69964efecca380b96219e
treefa23d98c084668ad9bc2eabb24b12ce206de11af
parent4de2b1ea65e6b54cedfe56268a8bf8e9446addb0

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

2 files changed, 12 insertions(+), 0 deletions(-)

lib/std/debug.zig+1
...@@ -775,6 +775,7 @@ pub const StackIterator = struct {...@@ -775,6 +775,7 @@ pub const StackIterator = struct {
775 }775 }
776776
777 pub fn deinit(it: *StackIterator) void {777 pub fn deinit(it: *StackIterator) void {
778 it.ma.deinit();
778 if (have_ucontext and it.unwind_state != null) it.unwind_state.?.dwarf_context.deinit();779 if (have_ucontext and it.unwind_state != null) it.unwind_state.?.dwarf_context.deinit();
779 }780 }
780781
lib/std/debug/MemoryAccessor.zig+11
...@@ -25,6 +25,17 @@ pub const init: MemoryAccessor = .{...@@ -25,6 +25,17 @@ pub const init: MemoryAccessor = .{
25 },25 },
26};26};
2727
28pub 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
28fn read(ma: *MemoryAccessor, address: usize, buf: []u8) bool {39fn read(ma: *MemoryAccessor, address: usize, buf: []u8) bool {
29 switch (native_os) {40 switch (native_os) {
30 .linux => while (true) switch (ma.mem.handle) {41 .linux => while (true) switch (ma.mem.handle) {