From ae3bd19108291563a12ddcca016f76ca9e813cf2 Mon Sep 17 00:00:00 2001 From: Philip Withnall Date: Fri, 12 Apr 2024 15:13:33 +0100 Subject: [PATCH] gresource: Improve resource unregistration performance slightly Rather than iterating over the list twice: once to find the resource, and once to re-find its link and delete it, just use `g_list_delete_link()` to delete what was found. This has the lovely side-effect of squashing a false positive from scan-build, which thought there was a use-after-free of `resource` in the caller, due to `g_resource_unref()` being called on it here. Signed-off-by: Philip Withnall Helps: #1767 --- gio/gresource.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/gio/gresource.c b/gio/gresource.c index 8ce00d49d..d19adf312 100644 --- a/gio/gresource.c +++ b/gio/gresource.c @@ -1029,14 +1029,16 @@ g_resources_register_unlocked (GResource *resource) static void g_resources_unregister_unlocked (GResource *resource) { - if (g_list_find (registered_resources, resource) == NULL) + GList *resource_link = g_list_find (registered_resources, resource); + + if (resource_link == NULL) { g_warning ("Tried to remove not registered resource"); } else { - registered_resources = g_list_remove (registered_resources, resource); - g_resource_unref (resource); + g_resource_unref (resource_link->data); + registered_resources = g_list_delete_link (registered_resources, resource_link); } }