[evolution-data-server] book/cal-backend: Add some safety checks around pending_operations queue



commit e4ef081c440186c53f59408129792a4bd584bcc7
Author: Milan Crha <mcrha redhat com>
Date:   Mon Sep 27 15:24:27 2021 +0200

    book/cal-backend: Add some safety checks around pending_operations queue
    
    Hold the related mutex when accessing the queue in the dispose().
    Warn when the queue is not empty in the finalize().

 src/addressbook/libedata-book/e-book-backend.c | 5 +++++
 src/calendar/libedata-cal/e-cal-backend.c      | 4 +++-
 2 files changed, 8 insertions(+), 1 deletion(-)
---
diff --git a/src/addressbook/libedata-book/e-book-backend.c b/src/addressbook/libedata-book/e-book-backend.c
index 852d6e4c2..4457664f2 100644
--- a/src/addressbook/libedata-book/e-book-backend.c
+++ b/src/addressbook/libedata-book/e-book-backend.c
@@ -516,11 +516,15 @@ book_backend_dispose (GObject *object)
        priv->views = NULL;
        g_mutex_unlock (&priv->views_mutex);
 
+       g_mutex_lock (&priv->operation_lock);
+
        g_hash_table_remove_all (priv->operation_ids);
 
        while (!g_queue_is_empty (&priv->pending_operations))
                dispatch_node_free (g_queue_pop_head (&priv->pending_operations));
 
+       g_mutex_unlock (&priv->operation_lock);
+
        g_clear_object (&priv->blocked);
 
        /* Chain up to parent's dispose() method. */
@@ -539,6 +543,7 @@ book_backend_finalize (GObject *object)
 
        g_free (priv->cache_dir);
 
+       g_warn_if_fail (g_queue_is_empty (&priv->pending_operations));
        g_mutex_clear (&priv->operation_lock);
        g_hash_table_destroy (priv->operation_ids);
 
diff --git a/src/calendar/libedata-cal/e-cal-backend.c b/src/calendar/libedata-cal/e-cal-backend.c
index 59511940c..66e314c1b 100644
--- a/src/calendar/libedata-cal/e-cal-backend.c
+++ b/src/calendar/libedata-cal/e-cal-backend.c
@@ -869,11 +869,12 @@ cal_backend_dispose (GObject *object)
 
        g_mutex_lock (&priv->operation_lock);
        g_hash_table_remove_all (priv->operation_ids);
-       g_mutex_unlock (&priv->operation_lock);
 
        while (!g_queue_is_empty (&priv->pending_operations))
                dispatch_node_free (g_queue_pop_head (&priv->pending_operations));
 
+       g_mutex_unlock (&priv->operation_lock);
+
        g_clear_object (&priv->blocked);
 
        /* Chain up to parent's dispose() method. */
@@ -900,6 +901,7 @@ cal_backend_finalize (GObject *object)
        g_hash_table_destroy (priv->zone_cache);
        g_mutex_clear (&priv->zone_cache_lock);
 
+       g_warn_if_fail (g_queue_is_empty (&priv->pending_operations));
        g_mutex_clear (&priv->operation_lock);
        g_hash_table_destroy (priv->operation_ids);
 


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