[balsa/gmime3: 58/66] Check for NULL return



commit 30b0784666ccb2e1500da549bc8722a9f1e122d8
Author: Peter Bloomfield <PeterBloomfield bellsouth net>
Date:   Sun Nov 24 18:51:09 2019 -0500

    Check for NULL return
    
    from g_mime_utils_header_decode_date() and g_mime_message_get_date().

 libbalsa/body.c    |  6 ++++--
 libbalsa/message.c | 12 ++++++++----
 2 files changed, 12 insertions(+), 6 deletions(-)
---
diff --git a/libbalsa/body.c b/libbalsa/body.c
index 1e944df70..014aac7bb 100644
--- a/libbalsa/body.c
+++ b/libbalsa/body.c
@@ -118,8 +118,10 @@ libbalsa_message_body_extract_embedded_headers(GMimeMessage* msg)
        ehdr->subject = g_strdup(_("(No subject)"));
 
     datetime = g_mime_message_get_date(msg);
-    ehdr->date = g_date_time_to_unix(datetime);
-    g_date_time_unref(datetime);
+    if (datetime != NULL) {
+        ehdr->date = g_date_time_to_unix(datetime);
+        g_date_time_unref(datetime);
+    }
 
     return ehdr;
 }
diff --git a/libbalsa/message.c b/libbalsa/message.c
index d5fe255d7..b9c32cc17 100644
--- a/libbalsa/message.c
+++ b/libbalsa/message.c
@@ -999,8 +999,10 @@ lb_message_headers_basic_from_gmime(LibBalsaMessageHeaders *headers,
         GDateTime *datetime;
 
         datetime = g_mime_message_get_date(mime_msg);
-        headers->date = g_date_time_to_unix(datetime);
-        g_date_time_unref(datetime);
+        if (datetime != NULL) {
+            headers->date = g_date_time_to_unix(datetime);
+            g_date_time_unref(datetime);
+        }
     }
 
     if (headers->to_list == NULL)
@@ -1234,8 +1236,10 @@ lbmsg_set_header(LibBalsaMessage *message,
         GDateTime *datetime;
 
         datetime = g_mime_utils_header_decode_date(value);
-        message->headers->date = g_date_time_to_unix(datetime);
-        g_date_time_unref(datetime);
+        if (datetime != NULL) {
+            message->headers->date = g_date_time_to_unix(datetime);
+            g_date_time_unref(datetime);
+        }
     } else if ((message->headers->from == NULL) &&
                (g_ascii_strcasecmp(name, "From") == 0)) {
         message->headers->from = internet_address_list_parse(libbalsa_parser_options(), value);


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