From 7bc26579844b2027bcc5fdde5b6978ea108f3edf Mon Sep 17 00:00:00 2001 From: random human Date: Sun, 2 Sep 2018 20:52:09 +0530 Subject: [PATCH 1/7] Free unused pointer in x11/backend.c --- backend/x11/backend.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/backend/x11/backend.c b/backend/x11/backend.c index e0f5d6e7..0ff2925d 100644 --- a/backend/x11/backend.c +++ b/backend/x11/backend.c @@ -163,6 +163,8 @@ static bool backend_start(struct wlr_backend *backend) { 0, 0, 0); + + free(reply); } } #endif From 7105864e13c7a83f57d22edce619fe511a9d1342 Mon Sep 17 00:00:00 2001 From: random human Date: Sun, 2 Sep 2018 21:16:24 +0530 Subject: [PATCH 2/7] Handle setting keymap in examples more securely --- examples/multi-pointer.c | 14 ++++++++++---- examples/output-layout.c | 10 ++++++++-- examples/pointer.c | 10 ++++++++-- examples/rotation.c | 10 ++++++++-- examples/simple.c | 10 ++++++++-- examples/tablet.c | 10 ++++++++-- examples/touch.c | 10 ++++++++-- 7 files changed, 58 insertions(+), 16 deletions(-) diff --git a/examples/multi-pointer.c b/examples/multi-pointer.c index 958e90f6..87beafab 100644 --- a/examples/multi-pointer.c +++ b/examples/multi-pointer.c @@ -239,15 +239,21 @@ void new_input_notify(struct wl_listener *listener, void *data) { wlr_log(WLR_ERROR, "Failed to create XKB context"); exit(1); } - wlr_keyboard_set_keymap(device->keyboard, xkb_map_new_from_names(context, - &rules, XKB_KEYMAP_COMPILE_NO_FLAGS)); + struct xkb_keymap *keymap = xkb_map_new_from_names(context, &rules, + XKB_KEYMAP_COMPILE_NO_FLAGS); + if (!keymap) { + wlr_log(WLR_ERROR, "Failed to create XKB keymap"); + exit(1); + } + wlr_keyboard_set_keymap(device->keyboard, keymap); + xkb_keymap_unref(keymap); xkb_context_unref(context); break; case WLR_INPUT_DEVICE_POINTER:; - struct sample_cursor *cursor = calloc(1, sizeof(struct sample_cursor)); + struct sample_cursor *cursor = calloc(1, sizeof(struct sample_cursor)); struct sample_pointer *pointer = calloc(1, sizeof(struct sample_pointer)); pointer->device = device; - cursor->sample = sample; + cursor->sample = sample; cursor->device = device; cursor->cursor = wlr_cursor_create(); diff --git a/examples/output-layout.c b/examples/output-layout.c index 2bfc5923..3f9cf84e 100644 --- a/examples/output-layout.c +++ b/examples/output-layout.c @@ -239,8 +239,14 @@ void new_input_notify(struct wl_listener *listener, void *data) { wlr_log(WLR_ERROR, "Failed to create XKB context"); exit(1); } - wlr_keyboard_set_keymap(device->keyboard, xkb_map_new_from_names(context, - &rules, XKB_KEYMAP_COMPILE_NO_FLAGS)); + struct xkb_keymap *keymap = xkb_map_new_from_names(context, &rules, + XKB_KEYMAP_COMPILE_NO_FLAGS); + if (!keymap) { + wlr_log(WLR_ERROR, "Failed to create XKB keymap"); + exit(1); + } + wlr_keyboard_set_keymap(device->keyboard, keymap); + xkb_keymap_unref(keymap); xkb_context_unref(context); break; default: diff --git a/examples/pointer.c b/examples/pointer.c index f0d9fb4b..cc58c223 100644 --- a/examples/pointer.c +++ b/examples/pointer.c @@ -304,8 +304,14 @@ void new_input_notify(struct wl_listener *listener, void *data) { wlr_log(WLR_ERROR, "Failed to create XKB context"); exit(1); } - wlr_keyboard_set_keymap(device->keyboard, xkb_map_new_from_names(context, - &rules, XKB_KEYMAP_COMPILE_NO_FLAGS)); + struct xkb_keymap *keymap = xkb_map_new_from_names(context, &rules, + XKB_KEYMAP_COMPILE_NO_FLAGS); + if (!keymap) { + wlr_log(WLR_ERROR, "Failed to create XKB keymap"); + exit(1); + } + wlr_keyboard_set_keymap(device->keyboard, keymap); + xkb_keymap_unref(keymap); xkb_context_unref(context); break; default: diff --git a/examples/rotation.c b/examples/rotation.c index add7f42f..7cf5727b 100644 --- a/examples/rotation.c +++ b/examples/rotation.c @@ -188,8 +188,14 @@ void new_input_notify(struct wl_listener *listener, void *data) { wlr_log(WLR_ERROR, "Failed to create XKB context"); exit(1); } - wlr_keyboard_set_keymap(device->keyboard, xkb_map_new_from_names(context, - &rules, XKB_KEYMAP_COMPILE_NO_FLAGS)); + struct xkb_keymap *keymap = xkb_map_new_from_names(context, &rules, + XKB_KEYMAP_COMPILE_NO_FLAGS); + if (!keymap) { + wlr_log(WLR_ERROR, "Failed to create XKB keymap"); + exit(1); + } + wlr_keyboard_set_keymap(device->keyboard, keymap); + xkb_keymap_unref(keymap); xkb_context_unref(context); break; default: diff --git a/examples/simple.c b/examples/simple.c index 1125bd2a..e1c10906 100644 --- a/examples/simple.c +++ b/examples/simple.c @@ -141,8 +141,14 @@ void new_input_notify(struct wl_listener *listener, void *data) { wlr_log(WLR_ERROR, "Failed to create XKB context"); exit(1); } - wlr_keyboard_set_keymap(device->keyboard, xkb_map_new_from_names(context, - &rules, XKB_KEYMAP_COMPILE_NO_FLAGS)); + struct xkb_keymap *keymap = xkb_map_new_from_names(context, &rules, + XKB_KEYMAP_COMPILE_NO_FLAGS); + if (!keymap) { + wlr_log(WLR_ERROR, "Failed to create XKB keymap"); + exit(1); + } + wlr_keyboard_set_keymap(device->keyboard, keymap); + xkb_keymap_unref(keymap); xkb_context_unref(context); break; default: diff --git a/examples/tablet.c b/examples/tablet.c index 4817db4d..fad30d52 100644 --- a/examples/tablet.c +++ b/examples/tablet.c @@ -297,8 +297,14 @@ void new_input_notify(struct wl_listener *listener, void *data) { wlr_log(WLR_ERROR, "Failed to create XKB context"); exit(1); } - wlr_keyboard_set_keymap(device->keyboard, xkb_map_new_from_names(context, - &rules, XKB_KEYMAP_COMPILE_NO_FLAGS)); + struct xkb_keymap *keymap = xkb_map_new_from_names(context, &rules, + XKB_KEYMAP_COMPILE_NO_FLAGS); + if (!keymap) { + wlr_log(WLR_ERROR, "Failed to create XKB keymap"); + exit(1); + } + wlr_keyboard_set_keymap(device->keyboard, keymap); + xkb_keymap_unref(keymap); xkb_context_unref(context); break; case WLR_INPUT_DEVICE_TABLET_PAD:; diff --git a/examples/touch.c b/examples/touch.c index ba5d1e34..9ed20a28 100644 --- a/examples/touch.c +++ b/examples/touch.c @@ -210,8 +210,14 @@ void new_input_notify(struct wl_listener *listener, void *data) { wlr_log(WLR_ERROR, "Failed to create XKB context"); exit(1); } - wlr_keyboard_set_keymap(device->keyboard, xkb_map_new_from_names(context, - &rules, XKB_KEYMAP_COMPILE_NO_FLAGS)); + struct xkb_keymap *keymap = xkb_map_new_from_names(context, &rules, + XKB_KEYMAP_COMPILE_NO_FLAGS); + if (!keymap) { + wlr_log(WLR_ERROR, "Failed to create XKB keymap"); + exit(1); + } + wlr_keyboard_set_keymap(device->keyboard, keymap); + xkb_keymap_unref(keymap); xkb_context_unref(context); break; case WLR_INPUT_DEVICE_TOUCH:; From 568b0ffe2c84c4ac4f21287a29ec55d3530346f4 Mon Sep 17 00:00:00 2001 From: random human Date: Sun, 2 Sep 2018 22:23:02 +0530 Subject: [PATCH 3/7] Call wl_global_create first in case of failure --- types/tablet_v2/wlr_tablet_v2.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/types/tablet_v2/wlr_tablet_v2.c b/types/tablet_v2/wlr_tablet_v2.c index 45036839..e53b8051 100644 --- a/types/tablet_v2/wlr_tablet_v2.c +++ b/types/tablet_v2/wlr_tablet_v2.c @@ -294,13 +294,6 @@ struct wlr_tablet_manager_v2 *wlr_tablet_v2_create(struct wl_display *display) { return NULL; } - wl_signal_init(&tablet->events.destroy); - wl_list_init(&tablet->clients); - wl_list_init(&tablet->seats); - - tablet->display_destroy.notify = handle_display_destroy; - wl_display_add_destroy_listener(display, &tablet->display_destroy); - tablet->wl_global = wl_global_create(display, &zwp_tablet_manager_v2_interface, TABLET_MANAGER_VERSION, tablet, tablet_v2_bind); @@ -309,5 +302,12 @@ struct wlr_tablet_manager_v2 *wlr_tablet_v2_create(struct wl_display *display) { return NULL; } + wl_signal_init(&tablet->events.destroy); + wl_list_init(&tablet->clients); + wl_list_init(&tablet->seats); + + tablet->display_destroy.notify = handle_display_destroy; + wl_display_add_destroy_listener(display, &tablet->display_destroy); + return tablet; } From ef5df78a271e1450311c6ca329b32156ce4f49e9 Mon Sep 17 00:00:00 2001 From: random human Date: Mon, 3 Sep 2018 03:27:28 +0530 Subject: [PATCH 4/7] Destroy layout after display in examples/output-layout --- examples/output-layout.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/output-layout.c b/examples/output-layout.c index 3f9cf84e..2d1bc58b 100644 --- a/examples/output-layout.c +++ b/examples/output-layout.c @@ -291,6 +291,6 @@ int main(int argc, char *argv[]) { wlr_texture_destroy(state.cat_texture); - wlr_output_layout_destroy(state.layout); wl_display_destroy(state.display); + wlr_output_layout_destroy(state.layout); } From de16defb21801399d2f4715dd5820d2f5d2a9deb Mon Sep 17 00:00:00 2001 From: random human Date: Mon, 3 Sep 2018 03:27:56 +0530 Subject: [PATCH 5/7] Release registry pointer in examples/idle --- examples/idle.c | 1 + 1 file changed, 1 insertion(+) diff --git a/examples/idle.c b/examples/idle.c index 87a03924..3e1565ca 100644 --- a/examples/idle.c +++ b/examples/idle.c @@ -129,6 +129,7 @@ int main(int argc, char *argv[]) { wl_registry_add_listener(registry, ®istry_listener, NULL); wl_display_dispatch(display); wl_display_roundtrip(display); + free(registry); if (idle_manager == NULL) { fprintf(stderr, "display doesn't support idle protocol\n"); From 6af77e3d9eee492c80830f197354fdd676873469 Mon Sep 17 00:00:00 2001 From: random human Date: Mon, 3 Sep 2018 04:00:53 +0530 Subject: [PATCH 6/7] Release pointers in examples/multi-pointer --- examples/multi-pointer.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/examples/multi-pointer.c b/examples/multi-pointer.c index 87beafab..49670c39 100644 --- a/examples/multi-pointer.c +++ b/examples/multi-pointer.c @@ -330,6 +330,11 @@ int main(int argc, char *argv[]) { cursor_destroy(cursor); } + struct sample_pointer *pointer, *tmp_pointer; + wl_list_for_each_safe(pointer, tmp_pointer, &state.pointers, link) { + free(pointer); + } + wlr_xcursor_theme_destroy(theme); wlr_output_layout_destroy(state.layout); } From 9f511ae942b27c0012cfa39d9950326d7e79f120 Mon Sep 17 00:00:00 2001 From: random human Date: Mon, 3 Sep 2018 05:05:18 +0530 Subject: [PATCH 7/7] Remove listener link after tablet_manager destroy --- types/tablet_v2/wlr_tablet_v2.c | 1 + 1 file changed, 1 insertion(+) diff --git a/types/tablet_v2/wlr_tablet_v2.c b/types/tablet_v2/wlr_tablet_v2.c index e53b8051..eabf5119 100644 --- a/types/tablet_v2/wlr_tablet_v2.c +++ b/types/tablet_v2/wlr_tablet_v2.c @@ -283,6 +283,7 @@ void wlr_tablet_v2_destroy(struct wlr_tablet_manager_v2 *manager) { } wlr_signal_emit_safe(&manager->events.destroy, manager); + wl_list_remove(&manager->display_destroy.link); wl_global_destroy(manager->wl_global); free(manager); }