* check for a valid foldername
[modest] / src / modest-singletons.c
index c373988..e756b11 100644 (file)
@@ -166,31 +166,25 @@ modest_singletons_finalize (GObject *obj)
        ModestSingletonsPrivate *priv;
                
        priv = MODEST_SINGLETONS_GET_PRIVATE(obj);
-
+       
+       if (priv->window_mgr) {
+               modest_runtime_verify_object_last_ref(priv->window_mgr,"");
+               g_object_unref (G_OBJECT(priv->window_mgr));
+               priv->window_mgr = NULL;
+       }
+       
        if (priv->account_store) {
                modest_runtime_verify_object_last_ref(priv->account_store,"");
                g_object_unref (G_OBJECT(priv->account_store));
                priv->account_store = NULL;
        }
 
-       if (priv->account_mgr) {
-               modest_runtime_verify_object_last_ref(priv->account_mgr,"");
-               g_object_unref (G_OBJECT(priv->account_mgr));
-               priv->account_mgr = NULL;
-       }
-
        if (priv->email_clipboard) {
                modest_runtime_verify_object_last_ref(priv->email_clipboard,"");
                g_object_unref (G_OBJECT(priv->email_clipboard));
                priv->email_clipboard = NULL;
        }
 
-       if (priv->conf) {
-               modest_runtime_verify_object_last_ref(priv->conf,"");
-               g_object_unref (G_OBJECT(priv->conf));
-               priv->conf = NULL;
-       }
-
        if (priv->cache_mgr) {
                modest_runtime_verify_object_last_ref(priv->cache_mgr,"");
                g_object_unref (G_OBJECT(priv->cache_mgr));
@@ -214,13 +208,23 @@ modest_singletons_finalize (GObject *obj)
                g_object_unref (G_OBJECT(priv->mail_op_queue));
                priv->mail_op_queue = NULL;
        }
+
+       /* It is important that the account manager is uninitialized after
+        * the mail op queue is uninitialized because the mail op queue
+        * cancells any mail operations which in turn access the account
+        * manager (see modest_mail_operation_notify_end()). */
+       if (priv->account_mgr) {
+               modest_runtime_verify_object_last_ref(priv->account_mgr,"");
+               g_object_unref (G_OBJECT(priv->account_mgr));
+               priv->account_mgr = NULL;
+       }
        
-       if (priv->window_mgr) {
-               modest_runtime_verify_object_last_ref(priv->window_mgr,"");
-               g_object_unref (G_OBJECT(priv->window_mgr));
-               priv->window_mgr = NULL;
+       if (priv->conf) {
+               modest_runtime_verify_object_last_ref(priv->conf,"");
+               g_object_unref (G_OBJECT(priv->conf));
+               priv->conf = NULL;
        }
-
+       
        G_OBJECT_CLASS(parent_class)->finalize (obj);
 }