Clean up some memory leaks
This commit is contained in:
parent
eaf13f3bcf
commit
9856bc92ec
7 changed files with 43 additions and 11 deletions
|
@ -35,3 +35,7 @@ struct wlr_output *river_wlr_noop_add_output(struct wlr_backend *backend) {
|
|||
bool river_wlr_output_is_noop(struct wlr_output *output) {
|
||||
return wlr_output_is_noop(output);
|
||||
}
|
||||
|
||||
void river_wlr_backend_destory(struct wlr_backend *backend) {
|
||||
wlr_backend_destroy(backend);
|
||||
}
|
||||
|
|
|
@ -31,5 +31,6 @@ struct wlr_session *river_wlr_backend_get_session(struct wlr_backend *backend);
|
|||
struct wlr_backend *river_wlr_noop_backend_create(struct wl_display *display);
|
||||
struct wlr_output *river_wlr_noop_add_output(struct wlr_backend *backend);
|
||||
bool river_wlr_output_is_noop(struct wlr_output *output);
|
||||
void river_wlr_backend_destory(struct wlr_backend *backend);
|
||||
|
||||
#endif // RIVER_BINDINGS_H
|
||||
|
|
|
@ -62,6 +62,10 @@ pub fn init(self: *Self, allocator: *std.mem.Allocator) !void {
|
|||
|
||||
pub fn deinit(self: Self, allocator: *std.mem.Allocator) void {
|
||||
self.mode_to_id.deinit();
|
||||
for (self.modes.items) |*mode| mode.deinit();
|
||||
for (self.modes.items) |mode| {
|
||||
for (mode.items) |mapping| mapping.deinit(allocator);
|
||||
mode.deinit();
|
||||
}
|
||||
self.modes.deinit();
|
||||
self.float_filter.deinit();
|
||||
}
|
||||
|
|
|
@ -85,12 +85,13 @@ fn runCommand(
|
|||
const seat = self.server.input_manager.default_seat;
|
||||
|
||||
var args = std.ArrayList([]const u8).init(allocator);
|
||||
defer args.deinit();
|
||||
|
||||
var i: usize = 0;
|
||||
const data = @ptrCast([*]const u8, wl_array.?.data);
|
||||
while (i < wl_array.?.size) {
|
||||
const slice = std.mem.spanZ(@ptrCast([*:0]const u8, &data[i]));
|
||||
args.append(std.mem.dupe(allocator, u8, slice) catch unreachable) catch unreachable;
|
||||
args.append(slice) catch unreachable;
|
||||
|
||||
i += slice.len + 1;
|
||||
}
|
||||
|
|
|
@ -27,6 +27,7 @@ const DecorationManager = @import("DecorationManager.zig");
|
|||
decoration_manager: *DecorationManager,
|
||||
wlr_xdg_toplevel_decoration: *c.wlr_xdg_toplevel_decoration_v1,
|
||||
|
||||
listen_destroy: c.wl_listener,
|
||||
listen_request_mode: c.wl_listener,
|
||||
|
||||
pub fn init(
|
||||
|
@ -37,12 +38,24 @@ pub fn init(
|
|||
self.decoration_manager = decoration_manager;
|
||||
self.wlr_xdg_toplevel_decoration = wlr_xdg_toplevel_decoration;
|
||||
|
||||
self.listen_destroy.notify = handleDestroy;
|
||||
c.wl_signal_add(&self.wlr_xdg_toplevel_decoration.events.destroy, &self.listen_destroy);
|
||||
|
||||
self.listen_request_mode.notify = handleRequestMode;
|
||||
c.wl_signal_add(&self.wlr_xdg_toplevel_decoration.events.request_mode, &self.listen_request_mode);
|
||||
|
||||
handleRequestMode(&self.listen_request_mode, self.wlr_xdg_toplevel_decoration);
|
||||
}
|
||||
|
||||
fn handleDestroy(listener: ?*c.wl_listener, data: ?*c_void) callconv(.C) void {
|
||||
const self = @fieldParentPtr(Self, "listen_destroy", listener.?);
|
||||
const allocator = self.decoration_manager.server.allocator;
|
||||
const node = @fieldParentPtr(std.SinglyLinkedList(Self).Node, "data", self);
|
||||
|
||||
self.decoration_manager.decorations.remove(node);
|
||||
allocator.destroy(node);
|
||||
}
|
||||
|
||||
fn handleRequestMode(listener: ?*c.wl_listener, data: ?*c_void) callconv(.C) void {
|
||||
const self = @fieldParentPtr(Self, "listen_request_mode", listener.?);
|
||||
// TODO: we might need to take this configure serial and do a transaction
|
||||
|
|
|
@ -79,11 +79,17 @@ pub fn init(self: *Self, server: *Server) !void {
|
|||
}
|
||||
|
||||
pub fn deinit(self: *Self) void {
|
||||
while (self.outputs.pop()) |output_node| {
|
||||
output_node.data.deinit();
|
||||
self.server.allocator.destroy(output_node);
|
||||
}
|
||||
// Need to remove these listeners as the noop output will be destroyed with
|
||||
// the noop backend triggering the destroy event. However,
|
||||
// Output.handleDestroy is not intended to handle the noop output being
|
||||
// destroyed.
|
||||
c.wl_list_remove(&self.noop_output.listen_destroy.link);
|
||||
c.wl_list_remove(&self.noop_output.listen_frame.link);
|
||||
c.wl_list_remove(&self.noop_output.listen_mode.link);
|
||||
|
||||
c.wlr_output_layout_destroy(self.wlr_output_layout);
|
||||
|
||||
if (c.wl_event_source_remove(self.transaction_timer) < 0) unreachable;
|
||||
}
|
||||
|
||||
pub fn addOutput(self: *Self, wlr_output: *c.wlr_output) void {
|
||||
|
|
|
@ -136,13 +136,16 @@ pub fn init(self: *Self, allocator: *std.mem.Allocator) !void {
|
|||
/// Free allocated memory and clean up
|
||||
pub fn deinit(self: *Self) void {
|
||||
// Note: order is important here
|
||||
if (build_options.xwayland) {
|
||||
c.wlr_xwayland_destroy(self.wlr_xwayland);
|
||||
}
|
||||
if (build_options.xwayland) c.wlr_xwayland_destroy(self.wlr_xwayland);
|
||||
|
||||
c.wl_display_destroy_clients(self.wl_display);
|
||||
c.wl_display_destroy(self.wl_display);
|
||||
self.input_manager.deinit();
|
||||
|
||||
self.root.deinit();
|
||||
|
||||
c.wl_display_destroy(self.wl_display);
|
||||
c.river_wlr_backend_destory(self.noop_backend);
|
||||
|
||||
self.input_manager.deinit();
|
||||
self.config.deinit(self.allocator);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue