memory leaks

This commit is contained in:
Janis 2022-12-17 17:39:13 +01:00
parent 07eb3a9177
commit dd609d6d36

View file

@ -363,14 +363,6 @@ fn ListItem(comptime T: type) type {
link: list.Link, link: list.Link,
value: T = undefined, value: T = undefined,
fn create(ally: std.mem.Allocator, value: T) !*Self {
const self = try ally.create(Self);
self.init(value);
return self;
}
fn init(self: *Self, value: T) void { fn init(self: *Self, value: T) void {
self.value = value; self.value = value;
} }
@ -1127,11 +1119,40 @@ const State = struct {
} }
fn deinit(self: *Self) void { fn deinit(self: *Self) void {
self.ally.destroy(self.seats); defer self.ally.destroy(self);
self.ally.destroy(self.outputs);
self.ally.destroy(self);
// TODO: clean up wayland state var seats_iter = self.seats.safeIterator(.forward);
while (seats_iter.next()) |next| {
next.remove();
self.ally.destroy(next);
}
self.ally.destroy(self.seats);
var outputs_iter = self.outputs.safeIterator(.forward);
while (outputs_iter.next()) |next| {
next.remove();
self.ally.destroy(next);
}
self.ally.destroy(self.outputs);
if (self.shm) |p| {
p.destroy();
}
if (self.compositor) |p| {
p.destroy();
}
if (self.layer_shell) |p| {
p.destroy();
}
if (self.xdg_output_manager) |p| {
p.destroy();
}
self.registry.destroy();
self.ally.destroy(
self.registry_listener
);
} }
fn registryListener(registry: *wl.Registry, event: wl.Registry.Event, self: *Self) void { fn registryListener(registry: *wl.Registry, event: wl.Registry.Event, self: *Self) void {
@ -1153,13 +1174,15 @@ const State = struct {
} else if (std.cstr.cmp(global.interface, wl.Seat.getInterface().name) == 0) { } else if (std.cstr.cmp(global.interface, wl.Seat.getInterface().name) == 0) {
const seat = registry.bind(global.name, wl.Seat, 1) catch return; const seat = registry.bind(global.name, wl.Seat, 1) catch return;
if (ListItem(Seat).create(self.ally, Seat{.seat = seat}) catch null) |ele| { if (self.ally.create(ListItem(Seat)) catch null) |ele| {
ele.init(Seat{.seat = seat});
self.seats.append(ele); self.seats.append(ele);
} }
} else if (std.cstr.cmp(global.interface, wl.Output.getInterface().name) == 0) { } else if (std.cstr.cmp(global.interface, wl.Output.getInterface().name) == 0) {
const output = registry.bind(global.name, wl.Output, 3) catch return; const output = registry.bind(global.name, wl.Output, 3) catch return;
if (ListItem(Output).create(self.ally, Output{.output = output}) catch null) |ele| { if (self.ally.create(ListItem(Output)) catch null) |ele| {
ele.init(Output{.output = output});
self.outputs.append(ele); self.outputs.append(ele);
} }
} }
@ -1328,6 +1351,7 @@ const State = struct {
self.xdg_output_manager.destroy(); self.xdg_output_manager.destroy();
xkb.xkb_context_unref(self.xkb_context); xkb.xkb_context_unref(self.xkb_context);
self.registry.destroy(); self.registry.destroy();
self.ally.destroy(self.registry_listener);
self.ally.free(self.cursor_theme); self.ally.free(self.cursor_theme);
} }