config: fix leak of hashmap keys

This commit is contained in:
Isaac Freund 2020-06-26 12:58:11 +02:00
parent dfb03fd0cb
commit 558918d286
No known key found for this signature in database
GPG Key ID: 86DED400DDFD7A11
2 changed files with 8 additions and 2 deletions

View File

@ -62,7 +62,9 @@ pub fn init(self: *Self) !void {
self.mode_to_id = std.StringHashMap(usize).init(util.gpa); self.mode_to_id = std.StringHashMap(usize).init(util.gpa);
errdefer self.mode_to_id.deinit(); errdefer self.mode_to_id.deinit();
try self.mode_to_id.putNoClobber("normal", 0); const owned_slice = try std.mem.dupe(util.gpa, u8, "normal");
errdefer util.gpa.free(owned_slice);
try self.mode_to_id.putNoClobber(owned_slice, 0);
self.modes = std.ArrayList(std.ArrayList(Mapping)).init(util.gpa); self.modes = std.ArrayList(std.ArrayList(Mapping)).init(util.gpa);
errdefer self.modes.deinit(); errdefer self.modes.deinit();
@ -76,11 +78,15 @@ pub fn init(self: *Self) !void {
} }
pub fn deinit(self: Self) void { pub fn deinit(self: Self) void {
var it = self.mode_to_id.iterator();
while (it.next()) |kv| util.gpa.free(kv.key);
self.mode_to_id.deinit(); self.mode_to_id.deinit();
for (self.modes.items) |mode| { for (self.modes.items) |mode| {
for (mode.items) |mapping| mapping.deinit(util.gpa); for (mode.items) |mapping| mapping.deinit(util.gpa);
mode.deinit(); mode.deinit();
} }
self.modes.deinit(); self.modes.deinit();
self.float_filter.deinit(); self.float_filter.deinit();
} }

View File

@ -105,7 +105,7 @@ pub fn init(self: *Self, root: *Root, wlr_output: *c.wlr_output) !void {
self.master_factor = 0.6; self.master_factor = 0.6;
self.layout = try std.fmt.allocPrint(util.gpa, "full", .{}); self.layout = try std.mem.dupe(util.gpa, u8, "full");
self.status_trackers = std.SinglyLinkedList(OutputStatus).init(); self.status_trackers = std.SinglyLinkedList(OutputStatus).init();