tests: add destroy listener in ivi-layout test plugin

Fixes ASan reported leak:

Direct leak of 136 byte(s) in 1 object(s) allocated from:
    #0 0x7ff60173c518 in calloc (/lib/x86_64-linux-gnu/libasan.so.5+0xe9518)
    #1 0x7ff5fcfed3fa in zalloc ../../git/weston/include/libweston/zalloc.h:38
    #2 0x7ff5fcfed8bf in wet_module_init ../../git/weston/tests/ivi-layout-test-plugin.c:196
    #3 0x7ff60161bd81 in wet_load_module ../../git/weston/compositor/main.c:941
    #4 0x7ff60161c165 in load_modules ../../git/weston/compositor/main.c:1012
    #5 0x7ff60162ced9 in wet_main ../../git/weston/compositor/main.c:3441
    #6 0x559a98fd7d4c in execute_compositor ../../git/weston/tests/weston-test-fixture-compositor.c:432
    #7 0x559a98fdb780 in weston_test_harness_execute_as_client ../../git/weston/tests/weston-test-runner.c:528
    #8 0x559a98fcbc48 in fixture_setup ../../git/weston/tests/ivi-layout-test-client.c:48
    #9 0x559a98fcbcca in fixture_setup_run_ ../../git/weston/tests/ivi-layout-test-client.c:50
    #10 0x559a98fdbd35 in main ../../git/weston/tests/weston-test-runner.c:661
    #11 0x7ff60129109a in __libc_start_main ../csu/libc-start.c:308
    #12 0x559a98fcb769 in _start (/home/pq/build/weston-meson/tests/test-ivi-layout-client+0xd769)

This also plugs the leak on wl_global_create() error path, though it
cannot really be tested.

Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.com>
dev
Pekka Paalanen 3 years ago committed by Pekka Paalanen
parent fda3696ecf
commit 2dcc79f58e
  1. 23
      tests/ivi-layout-test-plugin.c

@ -90,6 +90,7 @@ struct test_context {
struct test_launcher { struct test_launcher {
struct weston_compositor *compositor; struct weston_compositor *compositor;
struct wl_listener destroy_listener;
struct test_context context; struct test_context context;
const struct ivi_layout_interface *layout_interface; const struct ivi_layout_interface *layout_interface;
}; };
@ -179,6 +180,16 @@ bind_runner(struct wl_client *client, void *data,
} }
} }
static void
test_launcher_destroy(struct wl_listener *l, void *data)
{
struct test_launcher *launcher;
launcher = wl_container_of(l, launcher, destroy_listener);
free(launcher);
}
WL_EXPORT int WL_EXPORT int
wet_module_init(struct weston_compositor *compositor, wet_module_init(struct weston_compositor *compositor,
int *argc, char *argv[]) int *argc, char *argv[])
@ -200,10 +211,20 @@ wet_module_init(struct weston_compositor *compositor,
launcher->compositor = compositor; launcher->compositor = compositor;
launcher->layout_interface = iface; launcher->layout_interface = iface;
if (!weston_compositor_add_destroy_listener_once(compositor,
&launcher->destroy_listener,
test_launcher_destroy)) {
free(launcher);
return -1;
}
if (wl_global_create(compositor->wl_display, if (wl_global_create(compositor->wl_display,
&weston_test_runner_interface, 1, &weston_test_runner_interface, 1,
launcher, bind_runner) == NULL) launcher, bind_runner) == NULL) {
wl_list_remove(&launcher->destroy_listener.link);
free(launcher);
return -1; return -1;
}
return 0; return 0;
} }

Loading…
Cancel
Save