gresource: Assert that resource has correct refcount when unregistering

This should fix a scan-build warning that `resource` is
used-after-freeing in the final `g_resource_unref()` call in
`g_static_resource_fini()`, as `g_resources_unregister_unlocked()` has
already unreffed it.

In reality, each resource has two strong refs on it while active, so the
second unref is correct.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
This commit is contained in:
Philip Withnall 2022-05-10 15:53:19 +01:00
parent c8ea8cafd1
commit 86927c39e0

View File

@ -1444,6 +1444,10 @@ g_static_resource_fini (GStaticResource *static_resource)
resource = g_atomic_pointer_get (&static_resource->resource);
if (resource)
{
/* There should be at least two references to the resource now: one for
* static_resource->resource, and one in the registered_resources list. */
g_assert (g_atomic_int_get (&resource->ref_count) >= 2);
g_atomic_pointer_set (&static_resource->resource, NULL);
g_resources_unregister_unlocked (resource);
g_resource_unref (resource);