[balsa] mailbox-imap: Plug memory leaks



commit f203712054d9cbe8d0c327329066c435a3f6a11e
Author: Peter Bloomfield <PeterBloomfield bellsouth net>
Date:   Tue Feb 19 14:13:47 2019 -0500

    mailbox-imap: Plug memory leaks
    
            * libbalsa/mailbox_imap.c (lbm_imap_get_msg_part_from_cache):
            plug memory leaks in error return paths;

 ChangeLog               |  5 +++++
 libbalsa/mailbox_imap.c | 26 ++++++++++++++------------
 2 files changed, 19 insertions(+), 12 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 046ffa314..49d0488f2 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2019-02-19  Peter Bloomfield  <pbloomfield bellsouth net>
+
+       * libbalsa/mailbox_imap.c (lbm_imap_get_msg_part_from_cache):
+       plug memory leaks in error return paths;
+
 2019-02-18  Peter Bloomfield  <pbloomfield bellsouth net>
 
        * src/balsa-mime-widget-image.c (img_check_size): avoid scan-build
diff --git a/libbalsa/mailbox_imap.c b/libbalsa/mailbox_imap.c
index 8992755b5..72bcd6078 100644
--- a/libbalsa/mailbox_imap.c
+++ b/libbalsa/mailbox_imap.c
@@ -2475,6 +2475,7 @@ lbm_imap_get_msg_part_from_cache(LibBalsaMessage * msg,
                message. This can be simulated by randomly
                disconnecting from the IMAP server. */
             fprintf(stderr, "Cannot find data for section %s\n", section);
+            g_strfreev(pair);
             return FALSE;
         }
         dt.block = g_malloc(dt.body->octets+1);
@@ -2507,25 +2508,26 @@ lbm_imap_get_msg_part_from_cache(LibBalsaMessage * msg,
         if(rc != IMR_OK) {
             fprintf(stderr, "Error fetching imap message no %lu section %s\n",
                     msg->msgno, section);
-            g_free(dt.block);
-            g_free(section); 
-            g_strfreev(pair);
-            g_free(part_name);
             g_set_error(err,
                         LIBBALSA_MAILBOX_ERROR, LIBBALSA_MAILBOX_ACCESS_ERROR,
                         _("Error fetching message from IMAP server: %s"), 
                         imap_mbox_handle_get_last_msg(mimap->handle));
+            g_free(dt.block);
+            g_free(section);
+            g_free(part_name);
+            g_strfreev(pair);
             return FALSE;
         }
         g_mkdir_with_parents(pair[0], S_IRUSR|S_IWUSR|S_IXUSR);
         fp = fopen(part_name, "wb+");
         if(!fp) {
-            g_free(section); 
-            g_strfreev(pair);
-            g_free(part_name);
             g_set_error(err,
                         LIBBALSA_MAILBOX_ERROR, LIBBALSA_MAILBOX_ACCESS_ERROR,
                         _("Cannot create temporary file"));
+            g_free(dt.block);
+            g_free(section);
+            g_free(part_name);
+            g_strfreev(pair);
             return FALSE;
         }
         if(ifbo == IMFB_NONE || dt.body->octets == 0) {
@@ -2546,10 +2548,10 @@ lbm_imap_get_msg_part_from_cache(LibBalsaMessage * msg,
             g_set_error(err,
                         LIBBALSA_MAILBOX_ERROR, LIBBALSA_MAILBOX_ACCESS_ERROR,
                         _("Cannot write to temporary file %s"), part_name);
-            g_free(section); 
-            g_strfreev(pair);
-            g_free(part_name);
             g_free(dt.block);
+            g_free(section);
+            g_free(part_name);
+            g_strfreev(pair);
             return FALSE; /* something better ? */
             }
         }
@@ -2565,9 +2567,9 @@ lbm_imap_get_msg_part_from_cache(LibBalsaMessage * msg,
         g_object_unref (parser);
     }
     g_object_unref (partstream);
-    g_free(section); 
-    g_strfreev(pair);
+    g_free(section);
     g_free(part_name);
+    g_strfreev(pair);
 
     return TRUE;
 }


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