[evolution] Ref/unref imbalance on a CamelFolder instance



commit f804af97fe6f315148e2d0d6dfb10cba00d281c1
Author: Milan Crha <mcrha redhat com>
Date:   Thu Feb 21 10:17:42 2019 +0100

    Ref/unref imbalance on a CamelFolder instance
    
    When doing searches in the Mail view in other than Current Folder context
    and then clearing the search text, the search folder in the background was
    not freed, instead of it the real folder, into which the view had been
    switched, had been unreffed one more time. That could cause some issue
    in the future or at the quit of the application.
    
    Few other things found during this fixed as well.
    
    Related to a downstream bug report:
    https://bugzilla.redhat.com/show_bug.cgi?id=1678440

 src/libemail-engine/e-mail-utils.c   |  4 ++--
 src/libemail-engine/mail-vfolder.c   |  1 +
 src/mail/importers/mail-importer.c   |  7 +++++--
 src/modules/mail/e-mail-shell-view.c | 24 +++++++++++++++---------
 4 files changed, 23 insertions(+), 13 deletions(-)
---
diff --git a/src/libemail-engine/e-mail-utils.c b/src/libemail-engine/e-mail-utils.c
index 9b43130475..8d5b65cbdd 100644
--- a/src/libemail-engine/e-mail-utils.c
+++ b/src/libemail-engine/e-mail-utils.c
@@ -923,11 +923,11 @@ em_utils_get_real_folder_and_message_uid (CamelFolder *folder,
                                else
                                        g_free (real_uid);
 
-                               g_clear_object (&mi);
-
                                if (out_real_folder)
                                        *out_real_folder = g_object_ref (real_folder);
 
+                               g_clear_object (&mi);
+
                                return;
                        }
 
diff --git a/src/libemail-engine/mail-vfolder.c b/src/libemail-engine/mail-vfolder.c
index e96cfa5c93..843d145264 100644
--- a/src/libemail-engine/mail-vfolder.c
+++ b/src/libemail-engine/mail-vfolder.c
@@ -839,6 +839,7 @@ rule_changed (EFilterRule *rule,
                G_LOCK (vfolder);
                if (g_hash_table_lookup_extended (
                                vfolder_hash, full_name, &key, &oldfolder)) {
+                       g_warn_if_fail (oldfolder == folder);
                        g_hash_table_remove (vfolder_hash, key);
                        g_free (key);
                        g_hash_table_insert (
diff --git a/src/mail/importers/mail-importer.c b/src/mail/importers/mail-importer.c
index 9c1f2df48b..1d3a7196e3 100644
--- a/src/mail/importers/mail-importer.c
+++ b/src/mail/importers/mail-importer.c
@@ -154,13 +154,16 @@ import_mbox_exec (struct _import_mbox_msg *m,
                return;
        }
 
-       if (m->uri == NULL || m->uri[0] == 0)
+       if (m->uri == NULL || m->uri[0] == 0) {
                folder = e_mail_session_get_local_folder (
                        m->session, E_MAIL_LOCAL_FOLDER_INBOX);
-       else
+               if (folder)
+                       g_object_ref (folder);
+       } else {
                folder = e_mail_session_uri_to_folder_sync (
                        m->session, m->uri, CAMEL_STORE_FOLDER_CREATE,
                        cancellable, error);
+       }
 
        if (folder == NULL)
                return;
diff --git a/src/modules/mail/e-mail-shell-view.c b/src/modules/mail/e-mail-shell-view.c
index 7449fe64bb..f7dd766f05 100644
--- a/src/modules/mail/e-mail-shell-view.c
+++ b/src/modules/mail/e-mail-shell-view.c
@@ -840,11 +840,13 @@ filter:
                em_folder_tree_get_selected (
                        folder_tree, &selected_store, &selected_folder_name);
                if (selected_store != NULL && selected_folder_name != NULL) {
-                       folder = camel_store_get_folder_sync (
+                       CamelFolder *sel_folder;
+
+                       sel_folder = camel_store_get_folder_sync (
                                selected_store, selected_folder_name,
                                0, NULL, NULL);
-                       e_mail_reader_set_folder (reader, folder);
-                       g_object_unref (folder);
+                       e_mail_reader_set_folder (reader, sel_folder);
+                       g_object_unref (sel_folder);
                }
 
                g_clear_object (&selected_store);
@@ -959,11 +961,13 @@ all_accounts:
                em_folder_tree_get_selected (
                        folder_tree, &selected_store, &selected_folder_name);
                if (selected_store != NULL && selected_folder_name != NULL) {
-                       folder = camel_store_get_folder_sync (
+                       CamelFolder *sel_folder;
+
+                       sel_folder = camel_store_get_folder_sync (
                                selected_store, selected_folder_name,
                                0, NULL, NULL);
-                       e_mail_reader_set_folder (reader, folder);
-                       g_object_unref (folder);
+                       e_mail_reader_set_folder (reader, sel_folder);
+                       g_object_unref (sel_folder);
                }
 
                g_clear_object (&selected_store);
@@ -1067,11 +1071,13 @@ current_account:
                em_folder_tree_get_selected (
                        folder_tree, &selected_store, &selected_folder_name);
                if (selected_store != NULL && selected_folder_name != NULL) {
-                       folder = camel_store_get_folder_sync (
+                       CamelFolder *sel_folder;
+
+                       sel_folder = camel_store_get_folder_sync (
                                selected_store, selected_folder_name,
                                0, NULL, NULL);
-                       e_mail_reader_set_folder (reader, folder);
-                       g_object_unref (folder);
+                       e_mail_reader_set_folder (reader, sel_folder);
+                       g_object_unref (sel_folder);
                }
 
                g_clear_object (&selected_store);


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