From 4c2a3dbe7b652e679c9228d7d8c81aa641bd968b Mon Sep 17 00:00:00 2001 From: duerpei Date: Mon, 14 Mar 2022 13:27:43 +0800 Subject: Fix potential memory leak of two pointers (xwayland and client) This backports four patches from weston to solve a memory leak problem These four patches are: https://gitlab.freedesktop.org/wayland/weston/-/commit/5a6604a7a2e52e5cd84c1f53724b3f7c325b5dff.patch https://gitlab.freedesktop.org/wayland/weston/-/commit/f53c05d3c2c19c139c52e9bd621c2654dd3dac69.patch https://gitlab.freedesktop.org/wayland/weston/-/commit/e2583ca0844bd7a8ce4fc94da9ad67edf49ffd45.patch https://gitlab.freedesktop.org/wayland/weston/-/commit/8740037a93c7c4400cc381ecf3009d1e4014be07.patch The following is the valgrind log: 160 bytes in 1 blocks are definitely lost in loss record 39 of 66 at 0x484B64C: calloc (in /usr/lib/valgrind/vgpreload_memcheck-arm64-linux.so) by 0x4A73C87: ??? (in /usr/lib/libweston-desktop-8.so.0.0.0) by 0x4A7184F: weston_desktop_create (in /usr/lib/libweston-desktop-8.so.0.0.0) by 0x487096B: ivi_desktop_init (in /usr/lib/agl-compositor/libexec_compositor.so.0.0.0) by 0x486F5E7: wet_main (in /usr/lib/agl-compositor/libexec_compositor.so.0.0.0) by 0x48B010F: (below main) (in /lib/libc-2.31.so) In agl-compositor/src/composiotr.c "ivi->desktop->compositor->xwayland" is zalloced by wet_main()->ivi_desktop_init()->weston_desktop_create()->weston_desktop_xwayland_init() "ivi->desktop->compositor->xwayland->client" is zalloced by wet_main()->ivi_desktop_init()->weston_desktop_create()->weston_desktop_xwayland_init()->weston_desktop_client_create() "ivi->desktop->compositor->xwayland" and "ivi->desktop->compositor->xwayland->client" The memory pointed to has not been released Now, I want to free the memory pointed by the two pointers. What can do this is the function of weston_desktop_xwayland_fini() in 0003-libweston-desktop-add-weston_desktop_xwayland_fini.patch And the submission of this patch depends on the first three patches, so I submitted these four patches. Bug-AGL: SPEC-4291 Signed-off-by: duerpei Change-Id: I3b1140e88eadad9e378c2bb43221026e280ecd90 Reviewed-on: https://gerrit.automotivelinux.org/gerrit/c/AGL/meta-agl/+/27257 Reviewed-by: Marius Vlad Reviewed-by: Jan-Simon Moeller Tested-by: Jenkins Job builder account --- .../0001-libweston-add-weston_layer_fini.patch | 82 ++++++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100644 meta-agl-core/recipes-graphics/wayland/weston/0001-libweston-add-weston_layer_fini.patch (limited to 'meta-agl-core/recipes-graphics/wayland/weston/0001-libweston-add-weston_layer_fini.patch') diff --git a/meta-agl-core/recipes-graphics/wayland/weston/0001-libweston-add-weston_layer_fini.patch b/meta-agl-core/recipes-graphics/wayland/weston/0001-libweston-add-weston_layer_fini.patch new file mode 100644 index 000000000..5b4fd04c4 --- /dev/null +++ b/meta-agl-core/recipes-graphics/wayland/weston/0001-libweston-add-weston_layer_fini.patch @@ -0,0 +1,82 @@ +From 8740037a93c7c4400cc381ecf3009d1e4014be07 Mon Sep 17 00:00:00 2001 +From: Pekka Paalanen +Upstream-Status: Backport +Date: Fri, 14 May 2021 14:29:40 +0300 +Subject: [PATCH] libweston: add weston_layer_fini() + +Layers did not have a fini sequence before, which means the compositor +layer list might have stale pointers temporarily when shutting down. A +bigger problem might be having views linger after the destruction of the +layer. + +These problems were not observed yet, but if they exist, this patch +should help to find them and then fix them. + +The check in weston_compositor_shutdown() is not an assert yet, because +it will trigger until all components call weston_layer_fini() correctly. +Some components do not even have a tear-down function to call it from at +all, like fullscreen-shell. + +The same with the check in weston_layer_fini(). + +Signed-off-by: Pekka Paalanen +--- + include/libweston/libweston.h | 2 ++ + libweston/compositor.c | 21 +++++++++++++++++++++ + 2 files changed, 23 insertions(+) + +diff --git a/include/libweston/libweston.h b/include/libweston/libweston.h +index 7e8e7a625..d9907de0d 100644 +--- a/include/libweston/libweston.h ++++ b/include/libweston/libweston.h +@@ -1637,6 +1637,8 @@ void + weston_layer_init(struct weston_layer *layer, + struct weston_compositor *compositor); + void ++weston_layer_fini(struct weston_layer *layer); ++void + weston_layer_set_position(struct weston_layer *layer, + enum weston_layer_position position); + void +diff --git a/libweston/compositor.c b/libweston/compositor.c +index dc6ecb2ce..c2da3a48c 100644 +--- a/libweston/compositor.c ++++ b/libweston/compositor.c +@@ -3243,6 +3243,21 @@ weston_layer_init(struct weston_layer *layer, + weston_layer_set_mask_infinite(layer); + } + ++/** Finalize the weston_layer struct. ++ * ++ * \param layer The layer to finalize. ++ */ ++WL_EXPORT void ++weston_layer_fini(struct weston_layer *layer) ++{ ++ wl_list_remove(&layer->link); ++ ++ if (!wl_list_empty(&layer->view_list.link)) ++ weston_log("BUG: finalizing a layer with views still on it.\n"); ++ ++ wl_list_remove(&layer->view_list.link); ++} ++ + /** Sets the position of the layer in the layer list. The layer will be placed + * below any layer with the same position value, if any. + * This function is safe to call if the layer is already on the list, but the +@@ -7738,6 +7753,12 @@ weston_compositor_shutdown(struct weston_compositor *ec) + weston_binding_list_destroy_all(&ec->debug_binding_list); + + weston_plane_release(&ec->primary_plane); ++ ++ weston_layer_fini(&ec->fade_layer); ++ weston_layer_fini(&ec->cursor_layer); ++ ++ if (!wl_list_empty(&ec->layer_list)) ++ weston_log("BUG: layer_list is not empty after shutdown. Calls to weston_layer_fini() are missing somwhere.\n"); + } + + /** weston_compositor_exit_with_code +-- +GitLab + -- cgit 1.2.3-korg