[balsa] mailbox-{remote,imap}: Simplify dispose() methods



commit 33ef92f82ab34d81fd9b25059aacfcffe654107f
Author: Peter Bloomfield <PeterBloomfield bellsouth net>
Date:   Sat Jul 6 10:18:48 2019 -0400

    mailbox-{remote,imap}: Simplify dispose() methods
    
    * libbalsa/mailbox_imap.c (libbalsa_mailbox_imap_dispose): the
      server will be destroyed in the parent-class (LibBalsaMailboxRemote)
      method;
    * libbalsa/mailbox_remote.c (libbalsa_mailbox_remote_dispose):
      chain up to the parent-class (LibBalsaMailbox) method, to make
      sure the mailbox is closed, before destroying the server.

 ChangeLog                 | 11 +++++++++++
 libbalsa/mailbox_imap.c   | 14 ++------------
 libbalsa/mailbox_remote.c |  4 ++++
 3 files changed, 17 insertions(+), 12 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 10063e910..d4b38ea20 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+2019-07-06  Peter Bloomfield  <pbloomfield bellsouth net>
+
+       mailbox-{remote,imap}: Simplify dispose() methods
+
+       * libbalsa/mailbox_imap.c (libbalsa_mailbox_imap_dispose): the
+         server will be destroyed in the parent-class (LibBalsaMailboxRemote)
+         method;
+       * libbalsa/mailbox_remote.c (libbalsa_mailbox_remote_dispose):
+         chain up to the parent-class (LibBalsaMailbox) method, to make
+         sure the mailbox is closed, before destroying the server.
+
 2019-07-05  Peter Bloomfield  <pbloomfield bellsouth net>
 
        mailbox-pop3: Declare it final
diff --git a/libbalsa/mailbox_imap.c b/libbalsa/mailbox_imap.c
index 7ca4c80ad..ef62a420f 100644
--- a/libbalsa/mailbox_imap.c
+++ b/libbalsa/mailbox_imap.c
@@ -273,29 +273,19 @@ libbalsa_mailbox_imap_init(LibBalsaMailboxImap * mailbox)
     mailbox->disconnected = FALSE;
 }
 
-/* libbalsa_mailbox_imap_finalize:
-   NOTE: we have to close mailbox ourselves without waiting for
-   LibBalsaMailbox::finalize because we want to destroy server as well,
-   and close requires server for proper operation.  
-*/
 static void
 libbalsa_mailbox_imap_dispose(GObject * object)
 {
     LibBalsaMailboxImap *mimap;
-    LibBalsaMailboxRemote *remote;
     LibBalsaServer *server;
 
     mimap = LIBBALSA_MAILBOX_IMAP(object);
-
-    g_assert(libbalsa_mailbox_get_open_ref(LIBBALSA_MAILBOX(mimap)) == 0);
-
-    remote = LIBBALSA_MAILBOX_REMOTE(object);
-    server = libbalsa_mailbox_remote_get_server(remote);
+    server = LIBBALSA_MAILBOX_REMOTE_SERVER(object);
     if (server != NULL) {
         g_signal_handlers_disconnect_matched(server,
                                              G_SIGNAL_MATCH_DATA, 0,
                                              (GQuark) 0, NULL, NULL,
-                                             remote);
+                                             mimap);
     }
 
     if (mimap->unread_update_id != 0) {
diff --git a/libbalsa/mailbox_remote.c b/libbalsa/mailbox_remote.c
index cafcfe542..006cb72d1 100644
--- a/libbalsa/mailbox_remote.c
+++ b/libbalsa/mailbox_remote.c
@@ -70,6 +70,10 @@ libbalsa_mailbox_remote_dispose(GObject * object)
     LibBalsaMailboxRemotePrivate *priv =
         libbalsa_mailbox_remote_get_instance_private(remote);
 
+    /* This will close the mailbox, if it is still open: */
+    G_OBJECT_CLASS(libbalsa_mailbox_remote_parent_class)->dispose(object);
+
+    /* Now it is safe to unref the server: */
     g_clear_object(&priv->server);
 }
 


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