From 7105864e13c7a83f57d22edce619fe511a9d1342 Mon Sep 17 00:00:00 2001 From: random human Date: Sun, 2 Sep 2018 21:16:24 +0530 Subject: 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(-) (limited to 'examples') 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:; -- cgit v1.2.3 From ef5df78a271e1450311c6ca329b32156ce4f49e9 Mon Sep 17 00:00:00 2001 From: random human Date: Mon, 3 Sep 2018 03:27:28 +0530 Subject: Destroy layout after display in examples/output-layout --- examples/output-layout.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'examples') 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); } -- cgit v1.2.3 From de16defb21801399d2f4715dd5820d2f5d2a9deb Mon Sep 17 00:00:00 2001 From: random human Date: Mon, 3 Sep 2018 03:27:56 +0530 Subject: Release registry pointer in examples/idle --- examples/idle.c | 1 + 1 file changed, 1 insertion(+) (limited to 'examples') 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"); -- cgit v1.2.3 From 6af77e3d9eee492c80830f197354fdd676873469 Mon Sep 17 00:00:00 2001 From: random human Date: Mon, 3 Sep 2018 04:00:53 +0530 Subject: Release pointers in examples/multi-pointer --- examples/multi-pointer.c | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'examples') 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); } -- cgit v1.2.3