[grilo-plugins] flickr: Don't mix xmlChar and gchar inside hash_table
- From: Bastien Nocera <hadess src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [grilo-plugins] flickr: Don't mix xmlChar and gchar inside hash_table
- Date: Thu, 29 Jun 2017 15:29:51 +0000 (UTC)
commit 2e25e54611009489db7582cd090e4a3a9c703e09
Author: Rafael Fonseca <r4f4rfs gmail com>
Date: Tue Jun 14 16:16:58 2016 +0200
flickr: Don't mix xmlChar and gchar inside hash_table
Mixing both types can be potentially bad since they use different
allocators. Instead, use the proper function for freeing memory from a
xmlChar.
https://bugzilla.gnome.org/show_bug.cgi?id=707643
src/flickr/gflickr.c | 28 ++++++++++++++++++++++------
1 files changed, 22 insertions(+), 6 deletions(-)
---
diff --git a/src/flickr/gflickr.c b/src/flickr/gflickr.c
index 13f32e2..e11c7ba 100644
--- a/src/flickr/gflickr.c
+++ b/src/flickr/gflickr.c
@@ -172,12 +172,14 @@ add_node (xmlNodePtr node, GHashTable *photo)
xmlAttrPtr attr;
for (attr = node->properties; attr != NULL; attr = attr->next) {
+ xmlChar *prop = xmlGetProp (node, attr->name);
+
g_hash_table_insert (photo,
g_strconcat ((const gchar *) node->name,
"_",
(const gchar *) attr->name,
NULL),
- (gchar *) xmlGetProp (node, attr->name));
+ prop);
}
}
@@ -187,7 +189,7 @@ get_photo (xmlNodePtr node)
GHashTable *photo = g_hash_table_new_full (g_str_hash,
g_str_equal,
g_free,
- g_free);
+ xmlFree);
/* Add photo node */
add_node (node, photo);
@@ -202,9 +204,11 @@ get_photo (xmlNodePtr node)
add_node (node, photo);
} else if (xmlStrcmp (node->name, (const xmlChar *) "title") == 0 ||
xmlStrcmp (node->name, (const xmlChar *) "description") == 0) {
+ xmlChar *content = xmlNodeGetContent (node);
+
g_hash_table_insert (photo,
g_strdup ((const gchar *) node->name),
- (gchar *) xmlNodeGetContent (node));
+ content);
}
node = node->next;
@@ -228,9 +232,12 @@ get_photoset (xmlNodePtr node)
node = node->xmlChildrenNode;
while (node) {
+ xmlChar *content = xmlNodeGetContent (node);
+
g_hash_table_insert (photoset,
g_strdup ((const gchar *) node->name),
- (gchar *) xmlNodeGetContent (node));
+ content);
+
node = node->next;
}
@@ -241,7 +248,13 @@ static gchar *
get_tag (xmlNodePtr node)
{
if (xmlStrcmp (node->name, (const xmlChar *) "tag") == 0) {
- return (gchar *) xmlNodeGetContent (node);
+ gchar *tag = NULL;
+ xmlChar *content = xmlNodeGetContent (node);
+
+ tag = g_strdup ((const gchar *)content);
+ xmlFree (content);
+
+ return tag;
} else {
return NULL;
}
@@ -257,9 +270,12 @@ get_token_info (xmlNodePtr node)
node = node->xmlChildrenNode;
while (node) {
+ xmlChar *content = xmlNodeGetContent (node);
+
g_hash_table_insert (token,
g_strdup ((const gchar *) node->name),
- (gchar *) xmlNodeGetContent (node));
+ content);
+
add_node (node, token);
node = node->next;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]