Fixed a few memory leaks in LDAP search results handling.
authorAndrej Kacian <ticho@claws-mail.org>
Wed, 12 Jul 2017 11:22:52 +0000 (13:22 +0200)
committerAndrej Kacian <ticho@claws-mail.org>
Wed, 12 Jul 2017 11:22:52 +0000 (13:22 +0200)
src/ldapctrl.c

index d830279..62adf5b 100644 (file)
@@ -629,15 +629,18 @@ char **ldapctl_full_attribute_array( LdapControl *ctl ) {
        }
 
        def = ldapctl_get_default_criteria_list();
+       node = def;
        
-       while (def) {
+       while (node) {
                if( g_list_find_custom(tmp, (gpointer)def->data, 
                                (GCompareFunc)strcmp2) == NULL) {
-                       tmp = g_list_append(tmp, g_strdup(def->data));
+                       tmp = g_list_append(tmp, g_strdup(node->data));
                }
-               def = def->next;
+               node = node->next;
        }
 
+       g_list_free_full(def, g_free);
+
        node = tmp;
        cnt = g_list_length( tmp );
        ptrArray = g_new0( char *, 1 + cnt);
@@ -660,6 +663,7 @@ void ldapctl_free_attribute_array( char **ptrArray ) {
 
        /* Clear array to NULL's */
        for( i = 0; ptrArray[i] != NULL; i++ ) {
+               g_free(ptrArray[i]);
                ptrArray[i] = NULL;
        }
        g_free( ptrArray );
@@ -747,8 +751,7 @@ GList *ldapctl_get_default_criteria_list() {
                else
                        item = g_strdup(criteria);
                debug_print("adding attribute to list: %s\n", item);
-               attr_list = g_list_append(attr_list, g_strdup(item));
-               g_free(item);
+               attr_list = g_list_append(attr_list, item);
        }
        g_strfreev(c_list);
        return attr_list;