[tracker] libtracker-data: Rework ontology_get_fts_properties()



commit 15120cc8d4159a7ffbd63f4cca5b890eeb4c7a0c
Author: Haithem BEN GHORBAL <haithem benghorbal gmail com>
Date:   Mon Feb 8 15:27:55 2016 +0100

    libtracker-data: Rework ontology_get_fts_properties()
    
    All callers require both hashtables, so remove NULL handling for those.
    Fixes a possible memory leak if fts_properties is NULL.

 src/libtracker-data/tracker-data-manager.c |   26 ++++++++------------------
 1 files changed, 8 insertions(+), 18 deletions(-)
---
diff --git a/src/libtracker-data/tracker-data-manager.c b/src/libtracker-data/tracker-data-manager.c
index 8ce13b9..c8dab4a 100644
--- a/src/libtracker-data/tracker-data-manager.c
+++ b/src/libtracker-data/tracker-data-manager.c
@@ -3619,16 +3619,12 @@ ontology_get_fts_properties (gboolean     only_new,
 {
        TrackerProperty **properties;
        gboolean has_new = FALSE;
-       GHashTable *hashtable;
        guint i, len;
 
        properties = tracker_ontologies_get_properties (&len);
-       hashtable = g_hash_table_new_full (g_str_hash, g_str_equal, NULL,
-                                          (GDestroyNotify) g_list_free);
-
-       if (multivalued) {
-               *multivalued = g_hash_table_new (g_str_hash, g_str_equal);
-       }
+       *multivalued = g_hash_table_new (g_str_hash, g_str_equal);
+       *fts_properties = g_hash_table_new_full (g_str_hash, g_str_equal,
+                                                NULL, (GDestroyNotify) g_list_free);
 
        for (i = 0; i < len; i++) {
                const gchar *name, *table_name;
@@ -3640,28 +3636,22 @@ ontology_get_fts_properties (gboolean     only_new,
 
                has_new |= tracker_property_get_is_new (properties[i]);
                table_name = tracker_property_get_table_name (properties[i]);
+               name = tracker_property_get_name (properties[i]);
+               list = g_hash_table_lookup (*fts_properties, table_name);
 
-               if (multivalued &&
-                   tracker_property_get_multiple_values (properties[i])) {
+               if (tracker_property_get_multiple_values (properties[i])) {
                        g_hash_table_insert (*multivalued, (gpointer) table_name,
-                                            GUINT_TO_POINTER (TRUE));
+                                            GUINT_TO_POINTER (TRUE));
                }
 
-               name = tracker_property_get_name (properties[i]);
-               list = g_hash_table_lookup (hashtable, table_name);
-
                if (!list) {
                        list = g_list_prepend (NULL, (gpointer) name);
-                       g_hash_table_insert (hashtable, (gpointer) table_name, list);
+                       g_hash_table_insert (*fts_properties, (gpointer) table_name, list);
                } else {
                        list = g_list_append (list, (gpointer) name);
                }
        }
 
-       if (fts_properties) {
-               *fts_properties = hashtable;
-       }
-
        return has_new;
 }
 


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