]> granicus.if.org Git - mutt/commitdiff
Keep hcache pointer in idata, open and close with mailbox
authorBrendan Cully <brendan@kublai.com>
Fri, 6 Apr 2007 00:33:47 +0000 (17:33 -0700)
committerBrendan Cully <brendan@kublai.com>
Fri, 6 Apr 2007 00:33:47 +0000 (17:33 -0700)
ChangeLog
imap/imap.c
imap/imap_private.h
imap/message.c
imap/util.c

index be4c1137f9894f02a0e1804623ba42663ea04993..5a27e34da8872218d9105099b9b1bfa624982b1f 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,4 +1,10 @@
-2007-04-05 15:21 -0700  Brendan Cully  <brendan@kublai.com>  (7cf4415ec23d)
+2007-04-05 17:07 -0700  Brendan Cully  <brendan@kublai.com>  (26b19fc9b78c)
+
+       * hcache.c: Do not cache some unsafe header fields.
+
+       * imap/message.c, mh.c: Small hcache-related memory leaks
+
+       * hcache.c, mh.c: Fix mh header caching (closes #2472)
 
        * configure.ac: Teach --with-gdbm to accept a prefix (closes #2413)
 
index ff939c1c81895d87809e8fbe551ff1585a50de19..406221f3090cc7edd9d6dfee473a44c3f9299d5f 100644 (file)
@@ -249,10 +249,7 @@ void imap_expunge_mailbox (IMAP_DATA* idata)
   int i, cacheno;
 
 #if USE_HCACHE
-  header_cache_t *hc;
   char uidbuf[32];
-
-  hc = imap_hcache_open (idata, idata->ctx->path);
 #endif
 
   for (i = 0; i < idata->ctx->msgcount; i++)
@@ -268,10 +265,10 @@ void imap_expunge_mailbox (IMAP_DATA* idata)
 
       imap_cache_del (idata, h);
 #if USE_HCACHE
-      if (hc)
+      if (idata->hcache)
       {
         sprintf (uidbuf, "/%u", HEADER_DATA(h)->uid);
-        mutt_hcache_delete (hc, uidbuf, imap_hcache_keylen);
+        mutt_hcache_delete (idata->hcache, uidbuf, imap_hcache_keylen);
       }
 #endif
 
@@ -288,10 +285,6 @@ void imap_expunge_mailbox (IMAP_DATA* idata)
     }
   }
 
-#if USE_HCACHE
-  mutt_hcache_close (hc);
-#endif
-
   /* We may be called on to expunge at any time. We can't rely on the caller
    * to always know to rethread */
   mx_update_tables (idata->ctx, 0);
@@ -749,6 +742,9 @@ int imap_open_mailbox (CONTEXT* ctx)
   ctx->hdrs = safe_calloc (count, sizeof (HEADER *));
   ctx->v2r = safe_calloc (count, sizeof (int));
   ctx->msgcount = 0;
+#ifdef USE_HCACHE
+  idata->hcache = imap_hcache_open (idata, idata->ctx->path);
+#endif
   if (count && (imap_read_headers (idata, 0, count-1) < 0))
   {
     mutt_error _("Error opening mailbox");
@@ -761,6 +757,9 @@ int imap_open_mailbox (CONTEXT* ctx)
   return 0;
 
  fail:
+#ifdef USE_HCACHE
+  mutt_hcache_close (idata->hcache);
+#endif
   if (idata->state == IMAP_SELECTED)
     idata->state = IMAP_AUTHENTICATED;
  fail_noidata:
@@ -1108,7 +1107,6 @@ int imap_sync_mailbox (CONTEXT* ctx, int expunge, int* index_hint)
   int n;
   int rc;
 #if USE_HCACHE
-  void* hc = NULL;
   char uidbuf[32];
 #endif
   
@@ -1155,11 +1153,6 @@ int imap_sync_mailbox (CONTEXT* ctx, int expunge, int* index_hint)
     }
   }
 
-#if USE_HCACHE
-  if (expunge && ctx->closing)
-    hc = imap_hcache_open (idata, idata->ctx->path);
-#endif
-
   /* save messages with real (non-flag) changes */
   for (n = 0; n < ctx->msgcount; n++)
   {
@@ -1168,10 +1161,10 @@ int imap_sync_mailbox (CONTEXT* ctx, int expunge, int* index_hint)
     if (h->deleted)
       imap_cache_del (idata, h);
 #if USE_HCACHE
-    if (hc && h->deleted)
+    if (idata->hcache && h->deleted)
     {
       sprintf (uidbuf, "/%u", HEADER_DATA(h)->uid);
-      mutt_hcache_delete (hc, uidbuf, imap_hcache_keylen);
+      mutt_hcache_delete (idata->hcache, uidbuf, imap_hcache_keylen);
     }
 #endif
     if (h->active && h->changed)
@@ -1271,9 +1264,6 @@ int imap_sync_mailbox (CONTEXT* ctx, int expunge, int* index_hint)
 
   rc = 0;
  out:
-#if USE_HCACHE
-  mutt_hcache_close (hc);
-#endif
   if (cmd.data)
     FREE (&cmd.data);
   if (appendctx)
@@ -1332,6 +1322,9 @@ int imap_close_mailbox (CONTEXT* ctx)
     }
   }
 
+#ifdef USE_HCACHE
+  mutt_hcache_close (idata->hcache);
+#endif
   mutt_bcache_close (&idata->bcache);
 
   return 0;
index 9022482ba86338c7ca01ed6b9554ae8fdd8c18f5..d7bde1d9b8e50a4c9e8dc53f522b9ee48daa75e7 100644 (file)
@@ -24,6 +24,9 @@
 #include "mutt_curses.h"
 #include "mutt_socket.h"
 #include "bcache.h"
+#ifdef USE_HCACHE
+#include "hcache.h"
+#endif
 
 /* -- symbols -- */
 #define IMAP_PORT 143
@@ -208,6 +211,9 @@ typedef struct
 
   /* all folder flags - system flags AND keywords */
   LIST *flags;
+#ifdef USE_HCACHE
+  header_cache_t *hcache;
+#endif
 } IMAP_DATA;
 /* I wish that were called IMAP_CONTEXT :( */
 
@@ -253,7 +259,7 @@ int imap_cache_del (IMAP_DATA* idata, HEADER* h);
 
 /* util.c */
 #ifdef USE_HCACHE
-void* imap_hcache_open (IMAP_DATA* idata, const char* path);
+header_cache_t* imap_hcache_open (IMAP_DATA* idata, const char* path);
 #endif
 
 int imap_continue (const char* msg, const char* resp);
index 7a91b7f24391d1f7e99abba1d715e1ae036e3b89..83d9b7773efaeecab830eefc7454ff4c7111e0bc 100644 (file)
@@ -75,7 +75,6 @@ int imap_read_headers (IMAP_DATA* idata, int msgbegin, int msgend)
   progress_t progress;
 
 #if USE_HCACHE
-  header_cache_t *hc = NULL;
   unsigned int *uid_validity = NULL;
   unsigned int *uidnext = NULL;
   int evalhc = 0;
@@ -121,13 +120,10 @@ int imap_read_headers (IMAP_DATA* idata, int msgbegin, int msgend)
   idata->newMailCount = 0;
 
 #if USE_HCACHE
-  if (!msgbegin)
-    hc = imap_hcache_open (idata, ctx->path);
-
-  if (hc)
+  if (idata->hcache)
   {
-    uid_validity = mutt_hcache_fetch_raw (hc, "/UIDVALIDITY", imap_hcache_keylen);
-    uidnext = mutt_hcache_fetch_raw (hc, "/UIDNEXT", imap_hcache_keylen);
+    uid_validity = mutt_hcache_fetch_raw (idata->hcache, "/UIDVALIDITY", imap_hcache_keylen);
+    uidnext = mutt_hcache_fetch_raw (idata->hcache, "/UIDNEXT", imap_hcache_keylen);
     if (uid_validity && uidnext && *uid_validity == idata->uid_validity
         && *uidnext > 0)
       evalhc = 1;
@@ -173,7 +169,7 @@ int imap_read_headers (IMAP_DATA* idata, int msgbegin, int msgend)
 
         idx = h.sid - 1;
         sprintf(uid_buf, "/%u", h.data->uid); /* XXX --tg 21:41 04-07-11 */
-        uid_validity = (unsigned int*)mutt_hcache_fetch (hc, uid_buf, &imap_hcache_keylen);
+        uid_validity = (unsigned int*)mutt_hcache_fetch (idata->hcache, uid_buf, &imap_hcache_keylen);
 
         if (uid_validity != NULL && *uid_validity == idata->uid_validity)
         {
@@ -209,7 +205,6 @@ int imap_read_headers (IMAP_DATA* idata, int msgbegin, int msgend)
         if (h.data)
           imap_free_header_data ((void**) &h.data);
         fclose (fp);
-        mutt_hcache_close (hc);
         return -1;
       }
     }
@@ -299,7 +294,7 @@ int imap_read_headers (IMAP_DATA* idata, int msgbegin, int msgend)
 
 #if USE_HCACHE
       sprintf(uid_buf, "/%u", h.data->uid);
-      mutt_hcache_store(hc, uid_buf, ctx->hdrs[idx], idata->uid_validity, &imap_hcache_keylen);
+      mutt_hcache_store(idata->hcache, uid_buf, ctx->hdrs[idx], idata->uid_validity, &imap_hcache_keylen);
 #endif /* USE_HCACHE */
 
       ctx->msgcount++;
@@ -312,9 +307,6 @@ int imap_read_headers (IMAP_DATA* idata, int msgbegin, int msgend)
       if (h.data)
         imap_free_header_data ((void**) &h.data);
       fclose (fp);
-#if USE_HCACHE
-      mutt_hcache_close (hc);
-#endif /* USE_HCACHE */
       return -1;
     }
 
@@ -333,7 +325,7 @@ int imap_read_headers (IMAP_DATA* idata, int msgbegin, int msgend)
   status->uidnext = maxuid + 1;
 
 #if USE_HCACHE
-  mutt_hcache_store_raw (hc, "/UIDVALIDITY", &idata->uid_validity,
+  mutt_hcache_store_raw (idata->hcache, "/UIDVALIDITY", &idata->uid_validity,
                          sizeof (idata->uid_validity), imap_hcache_keylen);
   if (maxuid && idata->uidnext < maxuid + 1)
   {
@@ -341,9 +333,8 @@ int imap_read_headers (IMAP_DATA* idata, int msgbegin, int msgend)
     idata->uidnext = maxuid + 1;
   }
   if (idata->uidnext > 1)
-    mutt_hcache_store_raw (hc, "/UIDNEXT", &idata->uidnext,
+    mutt_hcache_store_raw (idata->hcache, "/UIDNEXT", &idata->uidnext,
                           sizeof (idata->uidnext), imap_hcache_keylen);
-  mutt_hcache_close (hc);
 #endif /* USE_HCACHE */
 
   fclose(fp);
index 7fd0757afc54665aa016d36b1dc3471429cacd54..9499c176c38ce88f3b67f6040dca249ace7a13e6 100644 (file)
@@ -70,7 +70,7 @@ int imap_expand_path (char* path, size_t len)
 }
 
 #ifdef USE_HCACHE
-void* imap_hcache_open (IMAP_DATA* idata, const char* path)
+header_cache_t* imap_hcache_open (IMAP_DATA* idata, const char* path)
 {
   IMAP_MBOX mx;
   ciss_url_t url;