[balsa] Fix some Valgrind-detected issues



commit 71a0a5bdef237617a7a4563f485e86069b8a3b80
Author: Peter Bloomfield <PeterBloomfield bellsouth net>
Date:   Mon Jul 15 20:54:33 2019 -0400

    Fix some Valgrind-detected issues
    
    * libbalsa/filter-file.c (libbalsa_mailbox_filters_load_config):
      initialize LibBalsaMailboxFilter::when;
    * libbalsa/mailbox.c (libbalsa_mailbox_finalize): clear the
      GRecMutex;
    * libbalsa/mailbox_imap.c (libbalsa_mailbox_imap_load_envelope):
      do not leak an InternetAddressList;
      (get_struct_from_cache): do not leak GMimeMessage;
    * libbalsa/send.c (lbs_message_queue_real): ref the GMimeMessage
      to preserve it, and then unref it.

 ChangeLog               | 14 ++++++++++++++
 libbalsa/filter-file.c  |  1 +
 libbalsa/mailbox.c      | 38 +++++++-------------------------------
 libbalsa/mailbox_imap.c | 11 +++++++++--
 libbalsa/send.c         |  3 +++
 5 files changed, 34 insertions(+), 33 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index e8d8ad488..b0d9afee2 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,17 @@
+2019-07-15  Peter Bloomfield  <pbloomfield bellsouth net>
+
+       Fix some Valgrind-detected issues
+
+       * libbalsa/filter-file.c (libbalsa_mailbox_filters_load_config):
+       initialize LibBalsaMailboxFilter::when;
+       * libbalsa/mailbox.c (libbalsa_mailbox_finalize): clear the
+       GRecMutex;
+       * libbalsa/mailbox_imap.c (libbalsa_mailbox_imap_load_envelope):
+       do not leak an InternetAddressList;
+       (get_struct_from_cache): do not leak GMimeMessage;
+       * libbalsa/send.c (lbs_message_queue_real): ref the GMimeMessage
+       to preserve it, and then unref it.
+
 2019-07-13  Peter Bloomfield  <pbloomfield bellsouth net>
 
        balsa-message: Pass message headers to disposition-notify handler
diff --git a/libbalsa/filter-file.c b/libbalsa/filter-file.c
index 33cb52602..1f6ce0104 100644
--- a/libbalsa/filter-file.c
+++ b/libbalsa/filter-file.c
@@ -130,6 +130,7 @@ libbalsa_mailbox_filters_load_config(LibBalsaMailbox* mbox)
                LibBalsaMailboxFilter *mf = g_new(LibBalsaMailboxFilter, 1);
 
                mf->actual_filter = fil;
+                mf->when = FILTER_WHEN_NEVER; /* 0 */
                filters = g_slist_prepend(filters, mf);
            }
            else
diff --git a/libbalsa/mailbox.c b/libbalsa/mailbox.c
index a273ba0ef..70deec935 100644
--- a/libbalsa/mailbox.c
+++ b/libbalsa/mailbox.c
@@ -442,10 +442,6 @@ libbalsa_mailbox_index_set_flags(LibBalsaMailbox *mailbox,
     }
 }
 
-/* libbalsa_mailbox_finalize:
-   destroys mailbox. Must leave it in sane state.
-*/
-
 static void lbm_msgno_changed_expunged_cb(LibBalsaMailbox * mailbox,
                                           guint seqno);
 static void lbm_get_index_entry_expunged_cb(LibBalsaMailbox * mailbox,
@@ -457,64 +453,44 @@ libbalsa_mailbox_finalize(GObject * object)
     LibBalsaMailbox *mailbox = LIBBALSA_MAILBOX(object);
     LibBalsaMailboxPrivate *priv = libbalsa_mailbox_get_instance_private(mailbox);
 
+    g_rec_mutex_clear(&priv->rec_mutex);
 
     g_free(priv->config_prefix);
-    priv->config_prefix = NULL;
-
     g_free(priv->name);
-    priv->name = NULL;
-
     g_free(priv->url);
-    priv->url = NULL;
 
     libbalsa_condition_unref(priv->view_filter);
-    priv->view_filter = NULL;
-
     libbalsa_condition_unref(priv->persistent_view_filter);
-    priv->persistent_view_filter = NULL;
 
     g_slist_free_full(priv->filters, g_free);
-    priv->filters = NULL;
-    priv->filters_loaded = FALSE;
 
-    if (priv->msgnos_pending) {
+    if (priv->msgnos_pending != NULL) {
         g_signal_handlers_disconnect_by_func(mailbox,
                                              lbm_get_index_entry_expunged_cb,
                                              priv->msgnos_pending);
         g_array_free(priv->msgnos_pending, TRUE);
-        priv->msgnos_pending = NULL;
     }
 
-    if (priv->msgnos_changed) {
+    if (priv->msgnos_changed != NULL) {
         g_signal_handlers_disconnect_by_func(mailbox,
                                              lbm_msgno_changed_expunged_cb,
                                              priv->msgnos_changed);
         g_array_free(priv->msgnos_changed, TRUE);
-        priv->msgnos_changed = NULL;
     }
 
     libbalsa_mailbox_view_free(priv->view);
-    priv->view = NULL;
 
-    if (priv->changed_idle_id) {
+    if (priv->changed_idle_id != 0)
         g_source_remove(priv->changed_idle_id);
-        priv->changed_idle_id = 0;
-    }
 
-    if (priv->queue_check_idle_id) {
+    if (priv->queue_check_idle_id != 0)
         g_source_remove(priv->queue_check_idle_id);
-        priv->queue_check_idle_id = 0;
-    }
 
-    if (priv->need_threading_idle_id) {
+    if (priv->need_threading_idle_id != 0)
         g_source_remove(priv->need_threading_idle_id);
-        priv->need_threading_idle_id = 0;
-    }
 
-    if (priv->run_filters_idle_id) {
+    if (priv->run_filters_idle_id != 0)
         g_source_remove(priv->run_filters_idle_id);
-        priv->run_filters_idle_id = 0;
-    }
 
     G_OBJECT_CLASS(libbalsa_mailbox_parent_class)->finalize(object);
 }
diff --git a/libbalsa/mailbox_imap.c b/libbalsa/mailbox_imap.c
index d87bd6247..eb663b9a1 100644
--- a/libbalsa/mailbox_imap.c
+++ b/libbalsa/mailbox_imap.c
@@ -1999,6 +1999,7 @@ libbalsa_mailbox_imap_load_envelope(LibBalsaMailboxImap *mimap,
     ImapEnvelope *envelope;
     ImapMessage* imsg;
     gchar *hdr;
+    InternetAddressList *sender;
     
     g_return_val_if_fail(mimap->opened, FALSE);
     imsg = mi_get_imsg(mimap, libbalsa_message_get_msgno(message));
@@ -2019,8 +2020,11 @@ libbalsa_mailbox_imap_load_envelope(LibBalsaMailboxImap *mimap,
     libbalsa_message_set_length(message, imsg->rfc822size);
     envelope = imsg->envelope;
     libbalsa_message_set_subject_from_header(message, envelope->subject);
-    libbalsa_message_set_sender(message,
-        internet_address_new_list_from_imap_address_list(envelope->sender));
+
+    sender = internet_address_new_list_from_imap_address_list(envelope->sender);
+    libbalsa_message_set_sender(message, sender);
+    g_object_unref(sender);
+
     libbalsa_message_set_in_reply_to_from_string(message, envelope->in_reply_to);
     if (envelope->message_id != NULL) {
         gchar *message_id = g_mime_utils_decode_message_id(envelope->message_id);
@@ -2197,6 +2201,9 @@ get_struct_from_cache(LibBalsaMailbox *mailbox, LibBalsaMessage *message,
         headers->user_hdrs = libbalsa_message_user_hdrs_from_gmime(mime_msg);
         libbalsa_message_set_has_all_headers(message, TRUE);
     }
+
+    g_object_unref(mime_msg);
+
     return TRUE;
 }
 
diff --git a/libbalsa/send.c b/libbalsa/send.c
index 07753a65d..422b01d17 100644
--- a/libbalsa/send.c
+++ b/libbalsa/send.c
@@ -455,6 +455,8 @@ lbs_message_queue_real(LibBalsaMessage    *message,
         mime_msgs =
             g_mime_message_partial_split_message(mime_msg, big_message,
                                                  &nparts);
+
+        g_object_ref(mime_msg);
         rc = TRUE;
         for (i = 0; i < nparts; ++i) {
             if (nparts > 1) {
@@ -476,6 +478,7 @@ lbs_message_queue_real(LibBalsaMessage    *message,
         g_free(mime_msgs);
         /* Restore message's original mime_msg: */
         libbalsa_message_set_mime_message(message, mime_msg);
+        g_object_unref(mime_msg);
     } else {
         rc = libbalsa_message_copy(message, outbox, error);
     }


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