aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Dusan <michael.dusan@gmail.com>2025-01-30 09:27:32 -0500
committerAlex Rønne Petersen <alex@alexrp.com>2025-02-01 04:27:24 +0100
commitc44be99f1abff2ab67d69964efecca380b96219e (patch)
treefa23d98c084668ad9bc2eabb24b12ce206de11af
parent4de2b1ea65e6b54cedfe56268a8bf8e9446addb0 (diff)
downloadzig-c44be99f1abff2ab67d69964efecca380b96219e.tar.gz
zig-c44be99f1abff2ab67d69964efecca380b96219e.zip
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
-rw-r--r--lib/std/debug.zig1
-rw-r--r--lib/std/debug/MemoryAccessor.zig11
2 files changed, 12 insertions, 0 deletions
diff --git a/lib/std/debug.zig b/lib/std/debug.zig
index 8134194380..643dcf731a 100644
--- a/lib/std/debug.zig
+++ b/lib/std/debug.zig
@@ -775,6 +775,7 @@ pub const StackIterator = struct {
}
pub fn deinit(it: *StackIterator) void {
+ it.ma.deinit();
if (have_ucontext and it.unwind_state != null) it.unwind_state.?.dwarf_context.deinit();
}
diff --git a/lib/std/debug/MemoryAccessor.zig b/lib/std/debug/MemoryAccessor.zig
index 9f112262be..5f57ad5853 100644
--- a/lib/std/debug/MemoryAccessor.zig
+++ b/lib/std/debug/MemoryAccessor.zig
@@ -25,6 +25,17 @@ pub const init: MemoryAccessor = .{
},
};
+pub fn deinit(ma: *MemoryAccessor) void {
+ switch (native_os) {
+ .linux => switch (ma.mem.handle) {
+ -2, -1 => {},
+ else => ma.mem.close(),
+ },
+ else => {},
+ }
+ ma.* = undefined;
+}
+
fn read(ma: *MemoryAccessor, address: usize, buf: []u8) bool {
switch (native_os) {
.linux => while (true) switch (ma.mem.handle) {