|
|
f22654 |
From a09ea6bd74d6234be8456e7039403bc1c1d078bd Mon Sep 17 00:00:00 2001
|
|
|
f22654 |
From: Christophe Fergeau <cfergeau@redhat.com>
|
|
|
f22654 |
Date: Mon, 20 Jun 2016 12:05:48 +0200
|
|
|
f22654 |
Subject: [PATCH 1/4] xml-node: Use GString in rest_xml_node_print()
|
|
|
f22654 |
|
|
|
f22654 |
The current code is using xml = g_strconcat (xml, ...) which is causing
|
|
|
f22654 |
some leaks as g_strconcat returns a newly allocated string. Using
|
|
|
f22654 |
GString avoids this issue without constantly freeing the intermediate
|
|
|
f22654 |
strings.
|
|
|
f22654 |
|
|
|
f22654 |
This fixes multiple leaks like:
|
|
|
f22654 |
|
|
|
f22654 |
==16611== 18 bytes in 1 blocks are definitely lost in loss record 124 of 301
|
|
|
f22654 |
==16611== at 0x4C2BBAD: malloc (vg_replace_malloc.c:299)
|
|
|
f22654 |
==16611== by 0x5F5CE58: g_malloc (gmem.c:94)
|
|
|
f22654 |
==16611== by 0x5F75B8E: g_strconcat (gstrfuncs.c:585)
|
|
|
f22654 |
==16611== by 0x4E450CF: rest_xml_node_print (rest-xml-node.c:287)
|
|
|
f22654 |
==16611== by 0x4E451DA: rest_xml_node_print (rest-xml-node.c:305)
|
|
|
f22654 |
==16611== by 0x4E450F8: rest_xml_node_print (rest-xml-node.c:292)
|
|
|
f22654 |
==16611== by 0x4009A0: main (xml.c:40)
|
|
|
f22654 |
---
|
|
|
f22654 |
rest/rest-xml-node.c | 21 ++++++++++++---------
|
|
|
f22654 |
1 file changed, 12 insertions(+), 9 deletions(-)
|
|
|
f22654 |
|
|
|
f22654 |
diff --git a/rest/rest-xml-node.c b/rest/rest-xml-node.c
|
|
|
f22654 |
index 57a942667f06..a8156dbbd432 100644
|
|
|
f22654 |
--- a/rest/rest-xml-node.c
|
|
|
f22654 |
+++ b/rest/rest-xml-node.c
|
|
|
f22654 |
@@ -283,38 +283,41 @@ rest_xml_node_print (RestXmlNode *node)
|
|
|
f22654 |
{
|
|
|
f22654 |
GHashTableIter iter;
|
|
|
f22654 |
gpointer key, value;
|
|
|
f22654 |
- char *xml = g_strconcat ("<", node->name, NULL);
|
|
|
f22654 |
+ GString *xml = g_string_new (NULL);
|
|
|
f22654 |
RestXmlNode *n;
|
|
|
f22654 |
|
|
|
f22654 |
+ g_string_append (xml, "<");
|
|
|
f22654 |
+ g_string_append (xml, node->name);
|
|
|
f22654 |
+
|
|
|
f22654 |
g_hash_table_iter_init (&iter, node->attrs);
|
|
|
f22654 |
while (g_hash_table_iter_next (&iter, &key, &value))
|
|
|
f22654 |
- xml = g_strconcat (xml, " ", key, "=\'", value, "\'", NULL);
|
|
|
f22654 |
+ g_string_append_printf (xml, " %s =\'%s\'", (char *)key, (char *)value);
|
|
|
f22654 |
|
|
|
f22654 |
- xml = g_strconcat (xml, ">", NULL);
|
|
|
f22654 |
+ g_string_append (xml, ">");
|
|
|
f22654 |
|
|
|
f22654 |
g_hash_table_iter_init (&iter, node->children);
|
|
|
f22654 |
while (g_hash_table_iter_next (&iter, &key, &value))
|
|
|
f22654 |
{
|
|
|
f22654 |
char *child = rest_xml_node_print ((RestXmlNode *) value);
|
|
|
f22654 |
|
|
|
f22654 |
- xml = g_strconcat (xml, child, NULL);
|
|
|
f22654 |
+ g_string_append (xml, child);
|
|
|
f22654 |
g_free (child);
|
|
|
f22654 |
}
|
|
|
f22654 |
|
|
|
f22654 |
if (node->content)
|
|
|
f22654 |
- xml = g_strconcat (xml, node->content, "</", node->name, ">", NULL);
|
|
|
f22654 |
- else
|
|
|
f22654 |
- xml = g_strconcat (xml, "</", node->name, ">", NULL);
|
|
|
f22654 |
+ g_string_append (xml, node->content);
|
|
|
f22654 |
+
|
|
|
f22654 |
+ g_string_append_printf (xml, "</%s>", node->name);
|
|
|
f22654 |
|
|
|
f22654 |
for (n = node->next; n; n = n->next)
|
|
|
f22654 |
{
|
|
|
f22654 |
char *sibling = rest_xml_node_print (n);
|
|
|
f22654 |
|
|
|
f22654 |
- xml = g_strconcat (xml, sibling, NULL);
|
|
|
f22654 |
+ g_string_append (xml, sibling);
|
|
|
f22654 |
g_free (sibling);
|
|
|
f22654 |
}
|
|
|
f22654 |
|
|
|
f22654 |
- return xml;
|
|
|
f22654 |
+ return g_string_free (xml, FALSE);
|
|
|
f22654 |
}
|
|
|
f22654 |
|
|
|
f22654 |
/**
|
|
|
f22654 |
--
|
|
|
f22654 |
2.14.2
|
|
|
f22654 |
|
|
|
f22654 |
|
|
|
f22654 |
From a34d02947c4f102e6d16b9d328941a4b2946c8e8 Mon Sep 17 00:00:00 2001
|
|
|
f22654 |
From: Debarshi Ray <debarshir@gnome.org>
|
|
|
f22654 |
Date: Fri, 13 Oct 2017 18:53:39 +0200
|
|
|
f22654 |
Subject: [PATCH 2/4] xml-node: Remove stray blank space
|
|
|
f22654 |
|
|
|
f22654 |
This had broken tests/xml.c.
|
|
|
f22654 |
|
|
|
f22654 |
Fallout from 61a7b231bd8b9d1b8d02dca120389e79d38b428d
|
|
|
f22654 |
|
|
|
f22654 |
https://bugzilla.gnome.org/show_bug.cgi?id=788960
|
|
|
f22654 |
---
|
|
|
f22654 |
rest/rest-xml-node.c | 2 +-
|
|
|
f22654 |
1 file changed, 1 insertion(+), 1 deletion(-)
|
|
|
f22654 |
|
|
|
f22654 |
diff --git a/rest/rest-xml-node.c b/rest/rest-xml-node.c
|
|
|
f22654 |
index a8156dbbd432..d3a7c995affd 100644
|
|
|
f22654 |
--- a/rest/rest-xml-node.c
|
|
|
f22654 |
+++ b/rest/rest-xml-node.c
|
|
|
f22654 |
@@ -291,7 +291,7 @@ rest_xml_node_print (RestXmlNode *node)
|
|
|
f22654 |
|
|
|
f22654 |
g_hash_table_iter_init (&iter, node->attrs);
|
|
|
f22654 |
while (g_hash_table_iter_next (&iter, &key, &value))
|
|
|
f22654 |
- g_string_append_printf (xml, " %s =\'%s\'", (char *)key, (char *)value);
|
|
|
f22654 |
+ g_string_append_printf (xml, " %s=\'%s\'", (char *)key, (char *)value);
|
|
|
f22654 |
|
|
|
f22654 |
g_string_append (xml, ">");
|
|
|
f22654 |
|
|
|
f22654 |
--
|
|
|
f22654 |
2.14.2
|
|
|
f22654 |
|
|
|
f22654 |
|
|
|
f22654 |
From f184db2bff0618b99c4de3316082fe80439f124c Mon Sep 17 00:00:00 2001
|
|
|
f22654 |
From: Debarshi Ray <debarshir@gnome.org>
|
|
|
f22654 |
Date: Fri, 13 Oct 2017 19:14:16 +0200
|
|
|
f22654 |
Subject: [PATCH 3/4] xml-node: Define the order in which attributes & children
|
|
|
f22654 |
are printed
|
|
|
f22654 |
|
|
|
f22654 |
The order in which GHashTable returns its key-value pairs is undefined.
|
|
|
f22654 |
Therefore the output of rest_xml_node_print can change based on the
|
|
|
f22654 |
GHashTable implementation. While not strictly necessary, it would be
|
|
|
f22654 |
nice to avoid that. Having a stable order, even if it is not
|
|
|
f22654 |
documented and depends on the current RestXmlNode code, is handy for
|
|
|
f22654 |
testing.
|
|
|
f22654 |
|
|
|
f22654 |
This was the main reason behind the tests/xml.c breakage.
|
|
|
f22654 |
|
|
|
f22654 |
https://bugzilla.gnome.org/show_bug.cgi?id=788960
|
|
|
f22654 |
---
|
|
|
f22654 |
rest/rest-xml-node.c | 23 ++++++++++++++++++++++-
|
|
|
f22654 |
1 file changed, 22 insertions(+), 1 deletion(-)
|
|
|
f22654 |
|
|
|
f22654 |
diff --git a/rest/rest-xml-node.c b/rest/rest-xml-node.c
|
|
|
f22654 |
index d3a7c995affd..973ebcf6c3fa 100644
|
|
|
f22654 |
--- a/rest/rest-xml-node.c
|
|
|
f22654 |
+++ b/rest/rest-xml-node.c
|
|
|
f22654 |
@@ -283,6 +283,9 @@ rest_xml_node_print (RestXmlNode *node)
|
|
|
f22654 |
{
|
|
|
f22654 |
GHashTableIter iter;
|
|
|
f22654 |
gpointer key, value;
|
|
|
f22654 |
+ GList *attrs = NULL;
|
|
|
f22654 |
+ GList *children = NULL;
|
|
|
f22654 |
+ GList *l;
|
|
|
f22654 |
GString *xml = g_string_new (NULL);
|
|
|
f22654 |
RestXmlNode *n;
|
|
|
f22654 |
|
|
|
f22654 |
@@ -291,13 +294,29 @@ rest_xml_node_print (RestXmlNode *node)
|
|
|
f22654 |
|
|
|
f22654 |
g_hash_table_iter_init (&iter, node->attrs);
|
|
|
f22654 |
while (g_hash_table_iter_next (&iter, &key, &value))
|
|
|
f22654 |
- g_string_append_printf (xml, " %s=\'%s\'", (char *)key, (char *)value);
|
|
|
f22654 |
+ {
|
|
|
f22654 |
+ char *attr = g_strdup_printf ("%s=\'%s\'", (char *)key, (char *)value);
|
|
|
f22654 |
+ attrs = g_list_prepend (attrs, attr);
|
|
|
f22654 |
+ }
|
|
|
f22654 |
+
|
|
|
f22654 |
+ attrs = g_list_sort (attrs, (GCompareFunc) g_strcmp0);
|
|
|
f22654 |
+ for (l = attrs; l; l = l->next)
|
|
|
f22654 |
+ {
|
|
|
f22654 |
+ const char *attr = (const char *) l->data;
|
|
|
f22654 |
+ g_string_append_printf (xml, " %s", attr);
|
|
|
f22654 |
+ }
|
|
|
f22654 |
|
|
|
f22654 |
g_string_append (xml, ">");
|
|
|
f22654 |
|
|
|
f22654 |
g_hash_table_iter_init (&iter, node->children);
|
|
|
f22654 |
while (g_hash_table_iter_next (&iter, &key, &value))
|
|
|
f22654 |
+ children = g_list_prepend (children, key);
|
|
|
f22654 |
+
|
|
|
f22654 |
+ children = g_list_sort (children, (GCompareFunc) g_strcmp0);
|
|
|
f22654 |
+ for (l = children; l; l = l->next)
|
|
|
f22654 |
{
|
|
|
f22654 |
+ const char *name = (const char *) l->data;
|
|
|
f22654 |
+ RestXmlNode *value = (RestXmlNode *) g_hash_table_lookup (node->children, name);
|
|
|
f22654 |
char *child = rest_xml_node_print ((RestXmlNode *) value);
|
|
|
f22654 |
|
|
|
f22654 |
g_string_append (xml, child);
|
|
|
f22654 |
@@ -317,6 +336,8 @@ rest_xml_node_print (RestXmlNode *node)
|
|
|
f22654 |
g_free (sibling);
|
|
|
f22654 |
}
|
|
|
f22654 |
|
|
|
f22654 |
+ g_list_free_full (attrs, g_free);
|
|
|
f22654 |
+ g_list_free (children);
|
|
|
f22654 |
return g_string_free (xml, FALSE);
|
|
|
f22654 |
}
|
|
|
f22654 |
|
|
|
f22654 |
--
|
|
|
f22654 |
2.14.2
|
|
|
f22654 |
|
|
|
f22654 |
|
|
|
f22654 |
From e5ee6ef751ee5a38d7b9fadcd631cf6ecec7b240 Mon Sep 17 00:00:00 2001
|
|
|
f22654 |
From: Debarshi Ray <debarshir@gnome.org>
|
|
|
f22654 |
Date: Fri, 13 Oct 2017 19:16:55 +0200
|
|
|
f22654 |
Subject: [PATCH 4/4] tests: Re-enable the XML test
|
|
|
f22654 |
|
|
|
f22654 |
This reverts commit 2d1dbfe7073b1e153ff881426b40a9a517fb796b
|
|
|
f22654 |
|
|
|
f22654 |
https://bugzilla.gnome.org/show_bug.cgi?id=788960
|
|
|
f22654 |
---
|
|
|
f22654 |
tests/Makefile.am | 2 --
|
|
|
f22654 |
1 file changed, 2 deletions(-)
|
|
|
f22654 |
|
|
|
f22654 |
diff --git a/tests/Makefile.am b/tests/Makefile.am
|
|
|
f22654 |
index 5d77f9cf5445..5ffdd4634e9a 100644
|
|
|
f22654 |
--- a/tests/Makefile.am
|
|
|
f22654 |
+++ b/tests/Makefile.am
|
|
|
f22654 |
@@ -1,6 +1,4 @@
|
|
|
f22654 |
TESTS = proxy proxy-continuous threaded oauth oauth-async oauth2 flickr lastfm xml custom-serialize
|
|
|
f22654 |
-# TODO: fix this test case
|
|
|
f22654 |
-XFAIL_TESTS = xml
|
|
|
f22654 |
|
|
|
f22654 |
AM_CPPFLAGS = $(SOUP_CFLAGS) -I$(top_srcdir) $(GCOV_CFLAGS)
|
|
|
f22654 |
AM_LDFLAGS = $(SOUP_LIBS) $(GCOV_LDFLAGS) \
|
|
|
f22654 |
--
|
|
|
f22654 |
2.14.2
|
|
|
f22654 |
|