From 817fdb9009cd085a6e8b00a5fab207050cae5b1a Mon Sep 17 00:00:00 2001 From: Simon Ser Date: Wed, 2 Jun 2021 16:35:30 +0200 Subject: [PATCH] shm: add safety assertions Catch any API mis-use with an assert. This should abort when the user calls unreferences the pool more times than it's referenced. Also change the refcount check to explicitly check for positive counts. That makes the condition more readable. Signed-off-by: Simon Ser --- src/wayland-shm.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/wayland-shm.c b/src/wayland-shm.c index aa64ff3..85204e4 100644 --- a/src/wayland-shm.c +++ b/src/wayland-shm.c @@ -106,13 +106,15 @@ shm_pool_unref(struct wl_shm_pool *pool, bool external) { if (external) { pool->external_refcount--; + assert(pool->external_refcount >= 0); if (pool->external_refcount == 0) shm_pool_finish_resize(pool); } else { pool->internal_refcount--; + assert(pool->internal_refcount >= 0); } - if (pool->internal_refcount + pool->external_refcount) + if (pool->internal_refcount + pool->external_refcount > 0) return; munmap(pool->data, pool->size); -- 2.7.4