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 <contact@emersion.fr>
This commit is contained in:
Simon Ser 2021-06-02 16:35:30 +02:00
parent ccc9612e82
commit 817fdb9009

View file

@ -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);