[nautilus] search-engine-recent: make sure we ref self before each idle



commit 3464c318a0656d6409e6a032561becb01c0cf534
Author: Marco Trevisan (TreviƱo) <mail 3v1n0 net>
Date:   Mon Oct 15 13:42:03 2018 +0200

    search-engine-recent: make sure we ref self before each idle
    
    Always ref self engine in case we fire a new search_add_hits_idle, otherwise
    we'll wrongly unref it in the idle callback.
    This happens when skipping the search engine because recursive search is not
    enabled.
    
    Similar thing was done in commit 3eecada7ad7db8d66be24cfc4ba6677e33c7d6e1, but
    that might have caused a leak in case an idle was already set up.

 src/nautilus-search-engine-recent.c | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)
---
diff --git a/src/nautilus-search-engine-recent.c b/src/nautilus-search-engine-recent.c
index 54e6f605c..993374214 100644
--- a/src/nautilus-search-engine-recent.c
+++ b/src/nautilus-search-engine-recent.c
@@ -124,11 +124,12 @@ search_add_hits_idle (NautilusSearchEngineRecent *self,
 
     if (self->add_hits_idle_id != 0)
     {
+        g_list_free_full (hits, g_object_unref);
         return;
     }
 
     search_hits = g_new0 (SearchHitsData, 1);
-    search_hits->recent = self;
+    search_hits->recent = g_object_ref (self);
     search_hits->hits = hits;
 
     self->add_hits_idle_id = g_idle_add (search_thread_add_hits_idle, search_hits);
@@ -182,7 +183,7 @@ is_file_valid_recursive (NautilusSearchEngineRecent *self,
 static gpointer
 recent_thread_func (gpointer user_data)
 {
-    NautilusSearchEngineRecent *self = NAUTILUS_SEARCH_ENGINE_RECENT (user_data);
+    g_autoptr (NautilusSearchEngineRecent) self = NAUTILUS_SEARCH_ENGINE_RECENT (user_data);
     g_autoptr (GPtrArray) date_range = NULL;
     g_autoptr (GFile) query_location = NULL;
     GList *recent_items;
@@ -338,14 +339,14 @@ nautilus_search_engine_recent_start (NautilusSearchProvider *provider)
                               nautilus_query_get_recursive (self->query),
                               location))
     {
-        search_add_hits_idle (g_object_ref (self), NULL);
+        search_add_hits_idle (self, NULL);
         return;
     }
 
-    g_object_ref (self);
     self->cancellable = g_cancellable_new ();
+    thread = g_thread_new ("nautilus-search-recent", recent_thread_func,
+                           g_object_ref (self));
 
-    thread = g_thread_new ("nautilus-search-recent", recent_thread_func, self);
     g_object_notify (G_OBJECT (provider), "running");
 
     g_thread_unref (thread);


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