From 719ca873997c17ad24e2c4613f915f231dde622b Mon Sep 17 00:00:00 2001 From: Pekka Paalanen Date: Mon, 24 May 2021 16:53:40 +0300 Subject: [PATCH] desktop-shell: clean up shell_output better This fixes the following ASan detected leaks: Direct leak of 88 byte(s) in 1 object(s) allocated from: #0 0x7f8c3455f330 in __interceptor_malloc (/lib/x86_64-linux-gnu/libasan.so.5+0xe9330) #1 0x7f8c33c60906 in wl_event_loop_add_timer ../../git/wayland/src/event-loop.c:571 #2 0x7f8c2ff98f46 in shell_fade_init ../../git/weston/desktop-shell/shell.c:4211 #3 0x7f8c2ff9e1da in wet_shell_init ../../git/weston/desktop-shell/shell.c:5266 #4 0x7f8c3443ede5 in wet_load_shell ../../git/weston/compositor/main.c:956 #5 0x7f8c3444fdb9 in wet_main ../../git/weston/compositor/main.c:3434 #6 0x55878ad3bfc6 in execute_compositor ../../git/weston/tests/weston-test-fixture-compositor.c:432 #7 0x55878ad3f9fa in weston_test_harness_execute_as_client ../../git/weston/tests/weston-test-runner.c:528 #8 0x55878ad2fbd6 in fixture_setup ../../git/weston/tests/viewporter-test.c:46 #9 0x55878ad2fc58 in fixture_setup_run_ ../../git/weston/tests/viewporter-test.c:48 #10 0x55878ad3ffaf in main ../../git/weston/tests/weston-test-runner.c:661 #11 0x7f8c340b409a in __libc_start_main ../csu/libc-start.c:308 #12 0x55878ad2f769 in _start (/home/pq/build/weston-meson/tests/test-viewporter+0xc769) Indirect leak of 856 byte(s) in 1 object(s) allocated from: #0 0x7f8c3455f518 in calloc (/lib/x86_64-linux-gnu/libasan.so.5+0xe9518) #1 0x7f8c33c99b73 in zalloc ../../git/weston/include/libweston/zalloc.h:38 #2 0x7f8c33c9cfb1 in weston_surface_create ../../git/weston/libweston/compositor.c:574 #3 0x7f8c2ff98230 in shell_fade_create_surface_for_output ../../git/weston/desktop-shell/shell.c:4059 #4 0x7f8c2ff98df6 in shell_fade_init ../../git/weston/desktop-shell/shell.c:4202 #5 0x7f8c2ff9e1da in wet_shell_init ../../git/weston/desktop-shell/shell.c:5266 #6 0x7f8c3443ede5 in wet_load_shell ../../git/weston/compositor/main.c:956 #7 0x7f8c3444fdb9 in wet_main ../../git/weston/compositor/main.c:3434 #8 0x55878ad3bfc6 in execute_compositor ../../git/weston/tests/weston-test-fixture-compositor.c:432 #9 0x55878ad3f9fa in weston_test_harness_execute_as_client ../../git/weston/tests/weston-test-runner.c:528 #10 0x55878ad2fbd6 in fixture_setup ../../git/weston/tests/viewporter-test.c:46 #11 0x55878ad2fc58 in fixture_setup_run_ ../../git/weston/tests/viewporter-test.c:48 #12 0x55878ad3ffaf in main ../../git/weston/tests/weston-test-runner.c:661 #13 0x7f8c340b409a in __libc_start_main ../csu/libc-start.c:308 #14 0x55878ad2f769 in _start (/home/pq/build/weston-meson/tests/test-viewporter+0xc769) Indirect leak of 608 byte(s) in 1 object(s) allocated from: #0 0x7f8c3455f518 in calloc (/lib/x86_64-linux-gnu/libasan.so.5+0xe9518) #1 0x7f8c33c99b73 in zalloc ../../git/weston/include/libweston/zalloc.h:38 #2 0x7f8c33c9bed5 in weston_view_create ../../git/weston/libweston/compositor.c:365 #3 0x7f8c2ff98251 in shell_fade_create_surface_for_output ../../git/weston/desktop-shell/shell.c:4063 #4 0x7f8c2ff98df6 in shell_fade_init ../../git/weston/desktop-shell/shell.c:4202 #5 0x7f8c2ff9e1da in wet_shell_init ../../git/weston/desktop-shell/shell.c:5266 #6 0x7f8c3443ede5 in wet_load_shell ../../git/weston/compositor/main.c:956 #7 0x7f8c3444fdb9 in wet_main ../../git/weston/compositor/main.c:3434 #8 0x55878ad3bfc6 in execute_compositor ../../git/weston/tests/weston-test-fixture-compositor.c:432 #9 0x55878ad3f9fa in weston_test_harness_execute_as_client ../../git/weston/tests/weston-test-runner.c:528 #10 0x55878ad2fbd6 in fixture_setup ../../git/weston/tests/viewporter-test.c:46 #11 0x55878ad2fc58 in fixture_setup_run_ ../../git/weston/tests/viewporter-test.c:48 #12 0x55878ad3ffaf in main ../../git/weston/tests/weston-test-runner.c:661 #13 0x7f8c340b409a in __libc_start_main ../csu/libc-start.c:308 #14 0x55878ad2f769 in _start (/home/pq/build/weston-meson/tests/test-viewporter+0xc769) They were found with: ASAN_OPTIONS=fast_unwind_on_malloc=0,malloc_context_size=50 \ LSAN_OPTIONS=suppressions=/home/pq/git/weston/.gitlab-ci/leak-sanitizer.supp \ ./tests/test-viewporter test_viewporter_double_create Turns out shell_destroy() had an open-coded and outdated copy of the tear-down sequence, so fixing the leaks in only handle_output_destroy() was not enough. Signed-off-by: Pekka Paalanen --- desktop-shell/shell.c | 33 +++++++++++++++++++++++++-------- 1 file changed, 25 insertions(+), 8 deletions(-) diff --git a/desktop-shell/shell.c b/desktop-shell/shell.c index ce1c286b..f126393a 100644 --- a/desktop-shell/shell.c +++ b/desktop-shell/shell.c @@ -4866,14 +4866,25 @@ shell_output_changed_move_layer(struct desktop_shell *shell, } static void -handle_output_destroy(struct wl_listener *listener, void *data) +shell_output_destroy(struct shell_output *shell_output) { - struct shell_output *shell_output = - container_of(listener, struct shell_output, destroy_listener); struct desktop_shell *shell = shell_output->shell; shell_for_each_layer(shell, shell_output_changed_move_layer, NULL); + if (shell_output->fade.animation) { + weston_view_animation_destroy(shell_output->fade.animation); + shell_output->fade.animation = NULL; + } + + if (shell_output->fade.view) { + /* destroys the view as well */ + weston_surface_destroy(shell_output->fade.view->surface); + } + + if (shell_output->fade.startup_timer) + wl_event_source_remove(shell_output->fade.startup_timer); + if (shell_output->panel_surface) wl_list_remove(&shell_output->panel_surface_listener.link); if (shell_output->background_surface) @@ -4883,6 +4894,15 @@ handle_output_destroy(struct wl_listener *listener, void *data) free(shell_output); } +static void +handle_output_destroy(struct wl_listener *listener, void *data) +{ + struct shell_output *shell_output = + container_of(listener, struct shell_output, destroy_listener); + + shell_output_destroy(shell_output); +} + static void shell_resize_surface_to_output(struct desktop_shell *shell, struct weston_surface *surface, @@ -5014,11 +5034,8 @@ shell_destroy(struct wl_listener *listener, void *data) text_backend_destroy(shell->text_backend); input_panel_destroy(shell); - wl_list_for_each_safe(shell_output, tmp, &shell->output_list, link) { - wl_list_remove(&shell_output->destroy_listener.link); - wl_list_remove(&shell_output->link); - free(shell_output); - } + wl_list_for_each_safe(shell_output, tmp, &shell->output_list, link) + shell_output_destroy(shell_output); wl_list_remove(&shell->output_create_listener.link); wl_list_remove(&shell->output_move_listener.link);