From 352e91258b02b2b4b59ca53e1875ba05cf5e9747 Mon Sep 17 00:00:00 2001 From: Charlotte Meyer Date: Wed, 15 Jan 2020 20:52:26 +0000 Subject: [PATCH] Fix memleaks --- include/desktop/desktop.h | 1 + include/input/cursor.h | 1 + include/input/input.h | 1 + kiwmi/desktop/desktop.c | 6 ++++++ kiwmi/input/cursor.c | 16 ++++++++++++++++ kiwmi/input/input.c | 14 ++++++++++++++ kiwmi/server.c | 3 +++ 7 files changed, 42 insertions(+) diff --git a/include/desktop/desktop.h b/include/desktop/desktop.h index ee14f1a..7ea305e 100644 --- a/include/desktop/desktop.h +++ b/include/desktop/desktop.h @@ -32,5 +32,6 @@ struct kiwmi_desktop { }; bool desktop_init(struct kiwmi_desktop *desktop, struct wlr_renderer *renderer); +void desktop_fini(struct kiwmi_desktop *desktop); #endif /* KIWMI_DESKTOP_DESKTOP_H */ diff --git a/include/input/cursor.h b/include/input/cursor.h index 021ea8a..88cc49f 100644 --- a/include/input/cursor.h +++ b/include/input/cursor.h @@ -45,5 +45,6 @@ struct kiwmi_cursor_motion_event { struct kiwmi_cursor *cursor_create( struct kiwmi_server *server, struct wlr_output_layout *output_layout); +void cursor_destroy(struct kiwmi_cursor *cursor); #endif /* KIWMI_INPUT_CURSOR_H */ diff --git a/include/input/input.h b/include/input/input.h index 89f812f..f81d44c 100644 --- a/include/input/input.h +++ b/include/input/input.h @@ -22,5 +22,6 @@ struct kiwmi_input { }; bool input_init(struct kiwmi_input *input); +void input_fini(struct kiwmi_input *input); #endif /* KIWMI_INPUT_INPUT_H */ diff --git a/kiwmi/desktop/desktop.c b/kiwmi/desktop/desktop.c index 02034c7..f2c5bad 100644 --- a/kiwmi/desktop/desktop.c +++ b/kiwmi/desktop/desktop.c @@ -62,3 +62,9 @@ desktop_init(struct kiwmi_desktop *desktop, struct wlr_renderer *renderer) return true; } + +void +desktop_fini(struct kiwmi_desktop *desktop) +{ + wlr_output_layout_destroy(desktop->output_layout); +} diff --git a/kiwmi/input/cursor.c b/kiwmi/input/cursor.c index 8226dd1..145b75a 100644 --- a/kiwmi/input/cursor.c +++ b/kiwmi/input/cursor.c @@ -235,3 +235,19 @@ cursor_create( return cursor; } + +void +cursor_destroy(struct kiwmi_cursor *cursor) +{ + wlr_cursor_destroy(cursor->cursor); + wlr_xcursor_manager_destroy(cursor->xcursor_manager); + + wl_list_remove(&cursor->cursor_motion.link); + wl_list_remove(&cursor->cursor_motion_absolute.link); + wl_list_remove(&cursor->cursor_button.link); + wl_list_remove(&cursor->cursor_axis.link); + wl_list_remove(&cursor->cursor_frame.link); + wl_list_remove(&cursor->seat_request_set_cursor.link); + + free(cursor); +} diff --git a/kiwmi/input/input.c b/kiwmi/input/input.c index 0697d25..76acbfa 100644 --- a/kiwmi/input/input.c +++ b/kiwmi/input/input.c @@ -7,6 +7,8 @@ #include "input/input.h" +#include + #include #include #include @@ -88,3 +90,15 @@ input_init(struct kiwmi_input *input) return true; } + +void +input_fini(struct kiwmi_input *input) +{ + struct kiwmi_keyboard *keyboard; + struct kiwmi_keyboard *tmp; + wl_list_for_each_safe (keyboard, tmp, &input->keyboards, link) { + free(keyboard); + } + + cursor_destroy(input->cursor); +} diff --git a/kiwmi/server.c b/kiwmi/server.c index 5b4c8b3..4248af2 100644 --- a/kiwmi/server.c +++ b/kiwmi/server.c @@ -128,6 +128,9 @@ server_fini(struct kiwmi_server *server) wl_display_destroy_clients(server->wl_display); wl_display_destroy(server->wl_display); + desktop_fini(&server->desktop); + input_fini(&server->input); + luaK_destroy(server->lua); free(server->config_path);