[gnome-software/gnome-41: 1/3] gs-appstream: Fix a leak when iterating over XML nodes




commit 64a2e618c8786525ce95c2fd0075fea50a2b3b6c
Author: Philip Withnall <pwithnall endlessos org>
Date:   Tue Oct 5 21:02:40 2021 +0100

    gs-appstream: Fix a leak when iterating over XML nodes
    
    Signed-off-by: Philip Withnall <pwithnall endlessos org>

 lib/gs-appstream.c | 19 ++++++++++++++++++-
 1 file changed, 18 insertions(+), 1 deletion(-)
---
diff --git a/lib/gs-appstream.c b/lib/gs-appstream.c
index 68b8485bc..283186abe 100644
--- a/lib/gs-appstream.c
+++ b/lib/gs-appstream.c
@@ -44,6 +44,23 @@ gs_appstream_create_app (GsPlugin *plugin, XbSilo *silo, XbNode *component, GErr
        return g_steal_pointer (&app_new);
 }
 
+/* Helper function to do the equivalent of
+ *  *node = xb_node_get_next (*node)
+ * but with correct reference counting, since xb_node_get_next() returns a new
+ * ref. */
+static void
+node_set_to_next (XbNode **node)
+{
+       g_autoptr(XbNode) next_node = NULL;
+
+       g_assert (node != NULL);
+       g_assert (*node != NULL);
+
+       next_node = xb_node_get_next (*node);
+       g_object_unref (*node);
+       *node = g_steal_pointer (&next_node);
+}
+
 static gchar *
 gs_appstream_format_description (XbNode *root, GError **error)
 {
@@ -760,7 +777,7 @@ gs_appstream_refine_app_relation (GsPlugin        *plugin,
         * more <id/>, <modalias/>, <kernel/>, <memory/>, <firmware/>,
         * <control/> or <display_length/> elements. For the moment, we only
         * support some of these. */
-       for (g_autoptr(XbNode) child = xb_node_get_child (relation_node); child != NULL; child = 
xb_node_get_next (child)) {
+       for (g_autoptr(XbNode) child = xb_node_get_child (relation_node); child != NULL; node_set_to_next 
(&child)) {
                const gchar *item_kind = xb_node_get_element (child);
                g_autoptr(AsRelation) relation = as_relation_new ();
 


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