[evolution/gnome-3-32] Fix a crash when filling mail threaded view



commit 59c064359b88d7b9e11668c62e718e43e76afbae
Author: Milan Crha <mcrha redhat com>
Date:   Mon May 13 18:23:12 2019 +0200

    Fix a crash when filling mail threaded view
    
    There could happen a crash when a folder received an update and it
    had been shown in the message list in the threaded view. With a proper
    thread interleaving the main thread could use the CamelFolderThread
    structure, while another thread had been freeing its internal members.
    The fix is to not re-use existing CamelFolderThread structure and always
    build a new one. This makes the filling a bit quicker too.
    
    Reported downstream at:
    https://bugzilla.redhat.com/show_bug.cgi?id=1709367

 src/mail/message-list.c | 34 ++++------------------------------
 1 file changed, 4 insertions(+), 30 deletions(-)
---
diff --git a/src/mail/message-list.c b/src/mail/message-list.c
index b0583fdccb..03750e4457 100644
--- a/src/mail/message-list.c
+++ b/src/mail/message-list.c
@@ -565,25 +565,6 @@ regen_data_unref (RegenData *regen_data)
        }
 }
 
-static CamelFolderThread *
-message_list_ref_thread_tree (MessageList *message_list)
-{
-       CamelFolderThread *thread_tree = NULL;
-
-       g_return_val_if_fail (IS_MESSAGE_LIST (message_list), NULL);
-
-       g_mutex_lock (&message_list->priv->thread_tree_lock);
-
-       if (message_list->priv->thread_tree != NULL) {
-               thread_tree = message_list->priv->thread_tree;
-               camel_folder_thread_messages_ref (thread_tree);
-       }
-
-       g_mutex_unlock (&message_list->priv->thread_tree_lock);
-
-       return thread_tree;
-}
-
 static void
 message_list_set_thread_tree (MessageList *message_list,
                               CamelFolderThread *thread_tree)
@@ -6128,17 +6109,10 @@ message_list_regen_thread (GSimpleAsyncResult *simple,
        if (regen_data->group_by_threads) {
                CamelFolderThread *thread_tree;
 
-               thread_tree = message_list_ref_thread_tree (message_list);
-
-               if (thread_tree != NULL) {
-                       /* Make sure multiple threads will not access the same
-                          CamelFolderThread structure at the same time */
-                       g_mutex_lock (&message_list->priv->thread_tree_lock);
-                       camel_folder_thread_messages_apply (thread_tree, uids);
-                       g_mutex_unlock (&message_list->priv->thread_tree_lock);
-               } else
-                       thread_tree = camel_folder_thread_messages_new (
-                               folder, uids, regen_data->thread_subject);
+               /* Always build a new thread_tree, to avoid race condition
+                  when accessing it here and in the build_tree() call
+                  from multiple threads. */
+               thread_tree = camel_folder_thread_messages_new (folder, uids, regen_data->thread_subject);
 
                /* We will build the ETreeModel content from this
                 * CamelFolderThread during regen post-processing.


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