From 74bfb8ba07cea0029b86f147834c2b271b38eba7 Mon Sep 17 00:00:00 2001 From: Jakub Konka Date: Thu, 21 Apr 2022 21:19:01 +0200 Subject: [PATCH] pdb: fix resource mgmt --- lib/std/pdb.zig | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/lib/std/pdb.zig b/lib/std/pdb.zig index 88ae849109..46078d6252 100644 --- a/lib/std/pdb.zig +++ b/lib/std/pdb.zig @@ -498,6 +498,15 @@ pub const Pdb = struct { symbols: []u8, subsect_info: []u8, checksum_offset: ?usize, + + pub fn deinit(self: *Module, allocator: mem.Allocator) void { + allocator.free(self.module_name); + allocator.free(self.obj_file_name); + if (self.populated) { + allocator.free(self.symbols); + allocator.free(self.subsect_info); + } + } }; pub fn init(allocator: mem.Allocator, path: []const u8) !Pdb { @@ -519,6 +528,10 @@ pub const Pdb = struct { pub fn deinit(self: *Pdb) void { self.in_file.close(); + self.msf.deinit(self.allocator); + for (self.modules) |*module| { + module.deinit(self.allocator); + } self.allocator.free(self.modules); self.allocator.free(self.sect_contribs); } @@ -941,6 +954,14 @@ const Msf = struct { .streams = streams, }; } + + fn deinit(self: *Msf, allocator: mem.Allocator) void { + allocator.free(self.directory.blocks); + for (self.streams) |*stream| { + allocator.free(stream.blocks); + } + allocator.free(self.streams); + } }; fn blockCountFromSize(size: u32, block_size: u32) u32 {