[gnome-software: 1/3] gs-appstream: Fix a leak when iterating over XML nodes
- From: Milan Crha <mcrha src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-software: 1/3] gs-appstream: Fix a leak when iterating over XML nodes
- Date: Wed, 6 Oct 2021 11:08:39 +0000 (UTC)
commit 8ddf0a2b5af885a4d4e293afb2aeb4ccbfb29b46
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]