[libgepub] lib: Fix memory leaks and warnings in gepub_utils_has_parent_tag()



commit 5ca8b09bdd8a7776db31ab6e2141138201545859
Author: Bastien Nocera <hadess hadess net>
Date:   Wed Jun 21 18:28:58 2017 +0200

    lib: Fix memory leaks and warnings in gepub_utils_has_parent_tag()
    
    Both the node name and what we were comparing it against were leaked at
    every iteration of the loop.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=784050

 libgepub/gepub-utils.c |   21 +++++++++++++++------
 1 files changed, 15 insertions(+), 6 deletions(-)
---
diff --git a/libgepub/gepub-utils.c b/libgepub/gepub-utils.c
index d120ffd..c380848 100644
--- a/libgepub/gepub-utils.c
+++ b/libgepub/gepub-utils.c
@@ -75,29 +75,38 @@ gepub_utils_has_parent_tag (xmlNode *node, gchar *name, ...)
     xmlNode *cur_node = NULL;
     GList *tags = NULL;
     GList *l = NULL;
-    gchar *name2 = NULL;
+    const char *name2 = NULL;
+    gboolean ret = FALSE;
 
     va_start (ap, name);
 
     for (name2 = name; name2 != NULL; name2 = va_arg(ap, gchar*)) {
-        tags = g_list_append (tags, name2);
+        tags = g_list_append (tags, g_ascii_strdown (name2, -1));
     }
 
     for (cur_node = node; cur_node; cur_node = cur_node->parent) {
         if (cur_node->type == XML_ELEMENT_NODE) {
             for (l = tags; l; l = l->next) {
-                gchar *nodetag = g_ascii_strup (cur_node->name, strlen (cur_node->name));
-                name2 = g_ascii_strup (l->data, strlen (l->data));
+                gchar *nodetag = g_ascii_strdown ((char *) cur_node->name, -1);
+                name2 = l->data;
 
                 if (!strcmp (nodetag, name2))
-                    return TRUE;
+                    ret = TRUE;
+
+                g_free (nodetag);
+
+                if (ret == TRUE)
+                  goto out;
             }
         }
     }
 
     va_end (ap);
 
-    return FALSE;
+out:
+    g_list_free_full (tags, g_free);
+
+    return ret;
 }
 
 /**


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