fix some memleaks

At this point, i don't get any memleaks caused by kiwmi. There may still
be some hidden ones though.
This commit is contained in:
tiosgz 2021-11-24 18:55:34 +00:00
parent e67f6c0113
commit d6ad004b58
6 changed files with 16 additions and 2 deletions

View file

@ -43,6 +43,7 @@ struct kiwmi_cursor {
struct {
struct wl_signal button_down;
struct wl_signal button_up;
struct wl_signal destroy;
struct wl_signal motion;
struct wl_signal scroll;
} events;

View file

@ -22,6 +22,10 @@ struct kiwmi_server {
struct kiwmi_lua *lua;
struct kiwmi_desktop desktop;
struct kiwmi_input input;
struct {
struct wl_signal destroy;
} events;
};
bool server_init(struct kiwmi_server *server, char *config_path);

View file

@ -254,6 +254,7 @@ cursor_create(
wl_signal_init(&cursor->events.button_down);
wl_signal_init(&cursor->events.button_up);
wl_signal_init(&cursor->events.destroy);
wl_signal_init(&cursor->events.motion);
wl_signal_init(&cursor->events.scroll);
@ -263,6 +264,8 @@ cursor_create(
void
cursor_destroy(struct kiwmi_cursor *cursor)
{
wl_signal_emit(&cursor->events.destroy, cursor);
wlr_cursor_destroy(cursor->cursor);
wlr_xcursor_manager_destroy(cursor->xcursor_manager);

View file

@ -309,7 +309,8 @@ luaK_kiwmi_cursor_new(lua_State *L)
struct kiwmi_lua *lua = lua_touserdata(L, 1);
struct kiwmi_cursor *cursor = lua_touserdata(L, 2);
struct kiwmi_object *obj = luaK_get_kiwmi_object(lua, cursor, NULL);
struct kiwmi_object *obj =
luaK_get_kiwmi_object(lua, cursor, &cursor->events.destroy);
struct kiwmi_object **cursor_ud = lua_newuserdata(L, sizeof(*cursor_ud));
luaL_getmetatable(L, "kiwmi_cursor");

View file

@ -574,7 +574,8 @@ luaK_kiwmi_server_new(lua_State *L)
struct kiwmi_lua *lua = lua_touserdata(L, 1);
struct kiwmi_server *server = lua_touserdata(L, 2);
struct kiwmi_object *obj = luaK_get_kiwmi_object(lua, server, NULL);
struct kiwmi_object *obj =
luaK_get_kiwmi_object(lua, server, &server->events.destroy);
struct kiwmi_object **server_ud = lua_newuserdata(L, sizeof(*server_ud));
luaL_getmetatable(L, "kiwmi_server");

View file

@ -46,6 +46,8 @@ server_init(struct kiwmi_server *server, char *config_path)
struct wlr_renderer *renderer = wlr_backend_get_renderer(server->backend);
wlr_renderer_init_wl_display(renderer, server->wl_display);
wl_signal_init(&server->events.destroy);
if (!desktop_init(&server->desktop, renderer)) {
wlr_log(WLR_ERROR, "Failed to initialize desktop");
wl_display_destroy(server->wl_display);
@ -132,6 +134,8 @@ server_fini(struct kiwmi_server *server)
{
wlr_log(WLR_DEBUG, "Shutting down Wayland server");
wl_signal_emit(&server->events.destroy, server);
wl_display_destroy_clients(server->wl_display);
desktop_fini(&server->desktop);