From b740e7f2d0404ef66b47882f5045b36d639eb0e8 Mon Sep 17 00:00:00 2001 From: buffet 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 6d71968..bf577e3 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 daeef3e..1e05e9f 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 afd8ddf..e3750ff 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 5fa1bc8..865a1e7 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 23981d7..6301760 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 d71a37c..63189af 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 207f7fa..d978671 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);