From 6da5b8a5a52efc8434fb83e1f43eb6da9c97dcc7 Mon Sep 17 00:00:00 2001 From: Leandro Ribeiro Date: Wed, 21 Feb 2024 13:08:42 -0300 Subject: [PATCH] color-noop: avoid assert hit in cmnoop_destroy() When we are destroying the color manager, the components referencing color profiles should have already been destroyed. We have an assert in cmnoop_destroy() to make sure that the stock profile has refcount equal to 1. But we currently have an issue in Weston. While shutting down with client surfaces alive, we may leak them. So we try to destroy the color manager with surfaces still alive, and they may be referencing color profiles. We already have a workaround for this in our LittleCMS color plugin, but we've missed that in color-noop. This fixes that, so now we don't hit the assert anymore. As we are already dealing with asserts in color-noop, I took the liberty to replace the last usage of assert with our own wrapper in this file. Signed-off-by: Leandro Ribeiro --- libweston/color-noop.c | 13 ++++++++++--- shared/weston-assert.h | 3 +++ 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/libweston/color-noop.c b/libweston/color-noop.c index 99b4e727..0bf994f2 100644 --- a/libweston/color-noop.c +++ b/libweston/color-noop.c @@ -174,11 +174,13 @@ static struct weston_output_color_outcome * cmnoop_create_output_color_outcome(struct weston_color_manager *cm_base, struct weston_output *output) { + struct weston_compositor *compositor = cm_base->compositor; struct weston_color_manager_noop *cmnoop = get_cmnoop(cm_base); struct weston_output_color_outcome *co; - assert(output->color_profile && - get_cprof(output->color_profile) == cmnoop->stock_cprof); + weston_assert_ptr(compositor, output->color_profile); + weston_assert_ptr_eq(compositor, get_cprof(output->color_profile), + cmnoop->stock_cprof); if (!check_output_eotf_mode(output)) return NULL; @@ -228,7 +230,12 @@ cmnoop_destroy(struct weston_color_manager *cm_base) { struct weston_color_manager_noop *cmnoop = get_cmnoop(cm_base); - assert(cmnoop->stock_cprof->base.ref_count == 1); + /* TODO: change this assert to make sure that ref_count is equal to 1. + * Currently we have a bug in which we leak surfaces when shutting down + * Weston with client surfaces alive, and these surfaces may have a + * reference to the stock sRGB profile. */ + weston_assert_uint32_gt_or_eq(cm_base->compositor, + cmnoop->stock_cprof->base.ref_count, 1); unref_cprof(cmnoop->stock_cprof); free(cmnoop); diff --git a/shared/weston-assert.h b/shared/weston-assert.h index 98c358c4..b934f57f 100644 --- a/shared/weston-assert.h +++ b/shared/weston-assert.h @@ -102,6 +102,9 @@ do { \ #define weston_assert_uint32_gt(compositor, a, b) \ weston_assert_(compositor, a, b, uint32_t, "%u", >) +#define weston_assert_uint32_gt_or_eq(compositor, a, b) \ + weston_assert_(compositor, a, b, uint32_t, "%u", >=) + #define weston_assert_uint32_lt(compositor, a, b) \ weston_assert_(compositor, a, b, uint32_t, "%u", <)