[bijiben] provider: Fix list of notes



commit 6c73a8b36738275c037d3be35076c307798baba4
Author: Isaque Galdino <igaldino gmail com>
Date:   Wed Apr 18 00:33:46 2018 -0300

    provider: Fix list of notes
    
    Local and OwnCloud providers keep lists (actually hash tables) of notes
    they are processing.
    
    Those lists were leaking memory because they were not releasing memory
    allocated by notes.
    
    Another problem was related to the hash table keys, not being properly
    saved in the hash table, making application to crash when cleaning up
    them.

 src/libbiji/provider/biji-local-provider.c     |    9 ++++++---
 src/libbiji/provider/biji-own-cloud-provider.c |    4 ++--
 2 files changed, 8 insertions(+), 5 deletions(-)
---
diff --git a/src/libbiji/provider/biji-local-provider.c b/src/libbiji/provider/biji-local-provider.c
index 3a8bd69..ebc4fa7 100644
--- a/src/libbiji/provider/biji-local-provider.c
+++ b/src/libbiji/provider/biji-local-provider.c
@@ -229,7 +229,7 @@ enumerate_next_files_ready_cb (GObject *source,
       else
         target = self->archives;
 
-      g_hash_table_replace (target, info.url, note);
+      g_hash_table_replace (target, g_strdup (info.url), note);
 
     }
 
@@ -342,6 +342,9 @@ biji_local_provider_finalize (GObject *object)
   g_object_unref (self->location);
   g_object_unref (self->trash_file);
 
+  g_hash_table_unref (self->items);
+  g_hash_table_unref (self->archives);
+
   biji_provider_helper_free (self->living_helper);
   biji_provider_helper_free (self->archives_helper);
 
@@ -353,8 +356,8 @@ static void
 biji_local_provider_init (BijiLocalProvider *self)
 {
   self->load_cancellable = g_cancellable_new ();
-  self->items = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, NULL);
-  self->archives = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, NULL);
+  self->items = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_object_unref);
+  self->archives = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_object_unref);
 
   /* Info */
   self->info.unique_id = "local";
diff --git a/src/libbiji/provider/biji-own-cloud-provider.c b/src/libbiji/provider/biji-own-cloud-provider.c
index b765367..f2eea33 100644
--- a/src/libbiji/provider/biji-own-cloud-provider.c
+++ b/src/libbiji/provider/biji-own-cloud-provider.c
@@ -181,7 +181,7 @@ create_note_from_item (BijiOCloudItem *item)
   biji_manager_get_default_color (manager, &color);
   biji_note_obj_set_rgba (note, &color);
   g_hash_table_replace (item->self->notes,
-                        item->set.url,
+                        g_strdup (item->set.url),
                         note);
 }
 
@@ -830,7 +830,7 @@ ocloud_prov_load_archives (BijiProvider *provider)
 static void
 biji_own_cloud_provider_init (BijiOwnCloudProvider *self)
 {
-  self->notes = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
+  self->notes = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_object_unref);
   self->tracker = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
   self->queue = g_queue_new ();
 }


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