[balsa] Handle GError pointer more carefully



commit 463f34365a4fbf691ebc22f4675536699ac2eb8d
Author: Peter Bloomfield <PeterBloomfield bellsouth net>
Date:   Wed Jun 28 17:36:42 2017 -0400

    Handle GError pointer more carefully
    
        * libbalsa/body.c
        (libbalsa_message_body_set_text_rfc822headers): do not create a
        GError and then ignore it;
        (libbalsa_message_body_get_stream): allow NULL GError pointer,
        and take more care in setting errors when it is non-NULL.

 ChangeLog       |   10 ++++++++++
 libbalsa/body.c |   30 +++++++++++++++++++-----------
 2 files changed, 29 insertions(+), 11 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 41b684f..20fcac8 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,15 @@
 2017-06-28  Peter Bloomfield  <pbloomfield bellsouth net>
 
+       Handle GError pointer more carefully
+
+       * libbalsa/body.c
+       (libbalsa_message_body_set_text_rfc822headers): do not create a
+       GError and then ignore it;
+       (libbalsa_message_body_get_stream): allow NULL GError pointer,
+       and take more care in setting errors when it is non-NULL.
+
+2017-06-28  Peter Bloomfield  <pbloomfield bellsouth net>
+
        Assert that a node is not NULL
 
        * libbalsa/mailbox.c (lbm_next): assert that node is not NULL
diff --git a/libbalsa/body.c b/libbalsa/body.c
index 6b2bdbc..caf68a2 100644
--- a/libbalsa/body.c
+++ b/libbalsa/body.c
@@ -217,13 +217,9 @@ static void
 libbalsa_message_body_set_text_rfc822headers(LibBalsaMessageBody *body)
 {
     GMimeStream *headers;
-    GError *err = NULL;
 
     libbalsa_mailbox_lock_store(body->message->mailbox);
-    headers = libbalsa_message_body_get_stream(body, &err);
-    if (err != NULL) {
-       g_error_free(err);
-    }
+    headers = libbalsa_message_body_get_stream(body, NULL);
 
     if (headers != NULL) {
        GMimeMessage *dummy_msg;
@@ -584,21 +580,33 @@ libbalsa_message_body_get_stream(LibBalsaMessageBody * body, GError **err)
     g_return_val_if_fail(body->message != NULL, NULL);
 
     if (!body->message->mailbox) {
-        g_set_error(err, LIBBALSA_MAILBOX_ERROR,
-                    LIBBALSA_MAILBOX_ACCESS_ERROR,
-                    "Internal error in get_stream");
+        if (err != NULL && *err == NULL) {
+            g_set_error(err, LIBBALSA_MAILBOX_ERROR,
+                        LIBBALSA_MAILBOX_ACCESS_ERROR,
+                        "Internal error in get_stream");
+        }
         return NULL;
     }
 
     if (!libbalsa_mailbox_get_message_part(body->message, body, err)
-        || !(GMIME_IS_PART(body->mime_part)
-             || GMIME_IS_MESSAGE_PART(body->mime_part))) {
-        if (err && !*err)
+        || body->mime_part == NULL) {
+        if (err != NULL && *err == NULL) {
+            g_set_error(err, LIBBALSA_MAILBOX_ERROR,
+                        LIBBALSA_MAILBOX_ACCESS_ERROR,
+                        "Cannot get stream for part");
+        }
+        return NULL;
+    }
+
+    if (!(GMIME_IS_PART(body->mime_part)
+          || GMIME_IS_MESSAGE_PART(body->mime_part))) {
+        if (err != NULL && *err == NULL) {
             g_set_error(err, LIBBALSA_MAILBOX_ERROR,
                         LIBBALSA_MAILBOX_ACCESS_ERROR,
                         "Cannot get stream for part of type %s",
                         g_type_name(G_TYPE_FROM_INSTANCE
                                     (body->mime_part)));
+        }
         return NULL;
     }
 


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