From 7dc716a2bbfd765171fff24257affb2b1eeb24f7 Mon Sep 17 00:00:00 2001 From: emersion Date: Tue, 31 Oct 2017 14:58:58 +0100 Subject: [PATCH] Fix memory leak in wlr_cursor --- examples/multi-pointer.c | 5 +++++ types/wlr_cursor.c | 20 ++++++++------------ 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/examples/multi-pointer.c b/examples/multi-pointer.c index e1ac2734..c69acc5f 100644 --- a/examples/multi-pointer.c +++ b/examples/multi-pointer.c @@ -212,6 +212,11 @@ int main(int argc, char *argv[]) { wl_display_run(compositor.display); compositor_fini(&compositor); + struct sample_cursor *cursor; + wl_list_for_each(cursor, &state.cursors, link) { + // TODO + } + wlr_xcursor_theme_destroy(theme); example_config_destroy(state.config); wlr_output_layout_destroy(state.layout); diff --git a/types/wlr_cursor.c b/types/wlr_cursor.c index e44b957a..83d36d14 100644 --- a/types/wlr_cursor.c +++ b/types/wlr_cursor.c @@ -98,7 +98,7 @@ struct wlr_cursor *wlr_cursor_create() { return cur; } -static void output_cursor_remove( +static void output_cursor_destroy( struct wlr_cursor_output_cursor *output_cursor) { wl_list_remove(&output_cursor->layout_output_destroy.link); wl_list_remove(&output_cursor->link); @@ -111,15 +111,10 @@ static void wlr_cursor_detach_output_layout(struct wlr_cursor *cur) { return; } - struct wlr_output_layout_output *l_output; - wl_list_for_each(l_output, &cur->state->layout->outputs, link) { - struct wlr_cursor_output_cursor *output_cursor, *tmp; - wl_list_for_each_safe(output_cursor, tmp, &cur->state->output_cursors, - link) { - if (output_cursor->output_cursor->output == l_output->output) { - output_cursor_remove(output_cursor); - } - } + struct wlr_cursor_output_cursor *output_cursor, *tmp; + wl_list_for_each_safe(output_cursor, tmp, &cur->state->output_cursors, + link) { + output_cursor_destroy(output_cursor); } wl_list_remove(&cur->state->layout_destroy.link); @@ -161,6 +156,7 @@ void wlr_cursor_destroy(struct wlr_cursor *cur) { wlr_cursor_device_destroy(device); } + free(cur->state); free(cur); } @@ -518,7 +514,7 @@ static void handle_layout_output_destroy(struct wl_listener *listener, struct wlr_cursor_output_cursor *output_cursor = wl_container_of(listener, output_cursor, layout_output_destroy); //struct wlr_output_layout_output *l_output = data; - output_cursor_remove(output_cursor); + output_cursor_destroy(output_cursor); } static void layout_add(struct wlr_cursor_state *state, @@ -542,7 +538,7 @@ static void layout_add(struct wlr_cursor_state *state, wl_signal_add(&l_output->events.destroy, &output_cursor->layout_output_destroy); - wl_list_insert(&state->cursor->state->output_cursors, &output_cursor->link); + wl_list_insert(&state->output_cursors, &output_cursor->link); } static void handle_layout_add(struct wl_listener *listener, void *data) {