[prev in list] [next in list] [prev in thread] [next in thread] 

List:       mutt-dev
Subject:    [PATCH] Make imap_free_header_data type-safe
From:       Andrew Gaul <andrew () gaul ! org>
Date:       2012-09-10 3:00:38
Message-ID: 4fa799cbf296ebd8fc7c.1347246038 () sherlock
[Download RAW message or body]

# HG changeset patch
# User Andrew Gaul <andrew@gaul.org>
# Date 1347245686 25200
# Branch HEAD
# Node ID 4fa799cbf296ebd8fc7ce0eacb05807fcfa30c4d
# Parent  70810a88ce9feb66d5c74e7ec3f2a633bd8b5312
Make imap_free_header_data type-safe

Also push conditional into function for safety and consistency with
other free functions.

diff -r 70810a88ce9f -r 4fa799cbf296 imap/imap_private.h
--- a/imap/imap_private.h	Sun Jul 22 11:15:30 2012 -0700
+++ b/imap/imap_private.h	Sun Sep 09 19:54:46 2012 -0700
@@ -256,7 +256,8 @@
 
 /* message.c */
 void imap_add_keywords (char* s, HEADER* keywords, LIST* mailbox_flags, size_t slen);
-void imap_free_header_data (void** data);
+struct imap_header_data;
+void imap_free_header_data (struct imap_header_data** data);
 int imap_read_headers (IMAP_DATA* idata, int msgbegin, int msgend);
 char* imap_set_flags (IMAP_DATA* idata, HEADER* h, char* s);
 int imap_cache_del (IMAP_DATA* idata, HEADER* h);
diff -r 70810a88ce9f -r 4fa799cbf296 imap/message.c
--- a/imap/message.c	Sun Jul 22 11:15:30 2012 -0700
+++ b/imap/message.c	Sun Sep 09 19:54:46 2012 -0700
@@ -160,8 +160,7 @@
         rc = imap_cmd_step (idata);
         if (rc != IMAP_CMD_CONTINUE)
 	{
-          /* suppress GCC aliasing warning */
-	  imap_free_header_data ((void**) (void*) &h.data);
+	  imap_free_header_data (&h.data);
           break;
 	}
 
@@ -173,7 +172,7 @@
           continue;
         else if (mfhrc < 0)
 	{
-	  imap_free_header_data ((void**) (void*) &h.data);
+	  imap_free_header_data (&h.data);
           break;
 	}
 
@@ -209,7 +208,7 @@
         {
 	  /* bad header in the cache, we'll have to refetch. */
           dprint (3, (debugfile, "bad cache entry at %d, giving up\n", h.sid - 1));
-          imap_free_header_data((void**) (void*) &h.data);
+          imap_free_header_data(&h.data);
           evalhc = 0;
           idx--;
         }
@@ -219,8 +218,7 @@
         break;
       if ((mfhrc < -1) || ((rc != IMAP_CMD_CONTINUE) && (rc != IMAP_CMD_OK)))
       {
-        if (h.data)
-          imap_free_header_data ((void**) (void*) &h.data);
+        imap_free_header_data (&h.data);
         imap_hcache_close (idata);
 	goto error_out_1;
       }
@@ -337,8 +335,7 @@
 
     if ((mfhrc < -1) || ((rc != IMAP_CMD_CONTINUE) && (rc != IMAP_CMD_OK)))
     {
-      if (h.data)
-        imap_free_header_data ((void**) (void*) &h.data);
+      imap_free_header_data (&h.data);
 #if USE_HCACHE
       imap_hcache_close (idata);
 #endif
@@ -1019,12 +1016,14 @@
 }
 
 /* imap_free_header_data: free IMAP_HEADER structure */
-void imap_free_header_data (void** data)
+void imap_free_header_data (IMAP_HEADER_DATA** data)
 {
-  /* this should be safe even if the list wasn't used */
-  mutt_free_list (&(((IMAP_HEADER_DATA*) *data)->keywords));
+  if (data) {
+    /* this should be safe even if the list wasn't used */
+    mutt_free_list (&((*data)->keywords));
 
-  FREE (data);		/* __FREE_CHECKED__ */
+    FREE (data);		/* __FREE_CHECKED__ */
+  }
 }
 
 /* imap_set_flags: fill out the message header according to the flags from
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic