[gnome-software: 1/5] gs-plugin-event: Split finalize and dispose vfuncs




commit bf337c41fd9f22bb4d58f8925a5a5745f0a5ebe8
Author: Philip Withnall <pwithnall endlessos org>
Date:   Fri Jan 28 13:31:43 2022 +0000

    gs-plugin-event: Split finalize and dispose vfuncs
    
    `dispose()` is needed to be able to clear refcounting loops. While I
    haven’t seen any of them, it’s possible that at some point a refcounting
    loop might exist between an app and an event, so split the vfuncs in
    case.
    
    Also tidy up the code to use ‘clear’ functions.
    
    Signed-off-by: Philip Withnall <pwithnall endlessos org>

 lib/gs-plugin-event.c | 22 ++++++++++++++++------
 1 file changed, 16 insertions(+), 6 deletions(-)
---
diff --git a/lib/gs-plugin-event.c b/lib/gs-plugin-event.c
index cc831b458..2fb56152e 100644
--- a/lib/gs-plugin-event.c
+++ b/lib/gs-plugin-event.c
@@ -273,17 +273,25 @@ gs_plugin_event_get_error (GsPluginEvent *event)
        return event->error;
 }
 
+static void
+gs_plugin_event_dispose (GObject *object)
+{
+       GsPluginEvent *event = GS_PLUGIN_EVENT (object);
+
+       g_clear_object (&event->app);
+       g_clear_object (&event->origin);
+
+       G_OBJECT_CLASS (gs_plugin_event_parent_class)->dispose (object);
+}
+
 static void
 gs_plugin_event_finalize (GObject *object)
 {
        GsPluginEvent *event = GS_PLUGIN_EVENT (object);
-       if (event->error != NULL)
-               g_error_free (event->error);
-       if (event->app != NULL)
-               g_object_unref (event->app);
-       if (event->origin != NULL)
-               g_object_unref (event->origin);
+
+       g_clear_error (&event->error);
        g_free (event->unique_id);
+
        G_OBJECT_CLASS (gs_plugin_event_parent_class)->finalize (object);
 }
 
@@ -291,6 +299,8 @@ static void
 gs_plugin_event_class_init (GsPluginEventClass *klass)
 {
        GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+       object_class->dispose = gs_plugin_event_dispose;
        object_class->finalize = gs_plugin_event_finalize;
 }
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]