]> granicus.if.org Git - neomutt/commitdiff
Do not hold hcache open while mailbox is open - it can lead to lockups
authorBrendan Cully <brendan@kublai.com>
Tue, 10 Apr 2007 23:07:53 +0000 (16:07 -0700)
committerBrendan Cully <brendan@kublai.com>
Tue, 10 Apr 2007 23:07:53 +0000 (16:07 -0700)
ChangeLog
imap/imap.c
imap/imap_private.h
imap/message.c
imap/util.c

index 2c43d7bb10737ae904f4b21a12acb5bc05f24cd7..af8e825304751c94cd48c974ed561a67d7c2b118 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,4 +1,9 @@
-2007-04-10 13:46 -0700  Brendan Cully  <brendan@kublai.com>  (d3e0d6c60d87)
+2007-04-10 15:32 -0700  Brendan Cully  <brendan@kublai.com>  (c38765da3fe8)
+
+       * imap/command.c, imap/imap.c, imap/imap_private.h, imap/util.c: Add
+       imap_hcache_del; minor cleanups
+
+       * main.c: Fix a compiler warning
 
        * rfc3676.c: Don't use $indent_string to quote replies to flowed
        messages (closes #2874).
index aeec066d42a297f1bebbef0833dd519bba458361..03d7298f22731e1dc63f4b85ad399e7eea729300 100644 (file)
@@ -248,6 +248,10 @@ void imap_expunge_mailbox (IMAP_DATA* idata)
   HEADER* h;
   int i, cacheno;
 
+#ifdef USE_HCACHE
+  imap_hcache_open (idata);
+#endif
+
   for (i = 0; i < idata->ctx->msgcount; i++)
   {
     h = idata->ctx->hdrs[i];
@@ -277,6 +281,10 @@ void imap_expunge_mailbox (IMAP_DATA* idata)
     }
   }
 
+#if USE_HCACHE
+  imap_hcache_close (idata);
+#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);
@@ -734,9 +742,7 @@ 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");
@@ -1139,6 +1145,10 @@ int imap_sync_mailbox (CONTEXT* ctx, int expunge, int* index_hint)
     }
   }
 
+#if USE_HCACHE
+  imap_hcache_open (idata);
+#endif
+
   /* save messages with real (non-flag) changes */
   for (n = 0; n < ctx->msgcount; n++)
   {
@@ -1174,6 +1184,10 @@ int imap_sync_mailbox (CONTEXT* ctx, int expunge, int* index_hint)
     }
   }
 
+#if USE_HCACHE
+  imap_hcache_close (idata);
+#endif
+
   /* sync +/- flags for the five flags mutt cares about */
   rc = 0;
 
@@ -1307,10 +1321,6 @@ int imap_close_mailbox (CONTEXT* ctx)
     }
   }
 
-#ifdef USE_HCACHE
-  mutt_hcache_close (idata->hcache);
-  idata->hcache = NULL;
-#endif
   mutt_bcache_close (&idata->bcache);
 
   return 0;
index b28e5ae30f122715c8bb659257e175f8558afffe..410f6bff0024274b608260494b2501c51c84dcd7 100644 (file)
@@ -259,7 +259,8 @@ int imap_cache_del (IMAP_DATA* idata, HEADER* h);
 
 /* util.c */
 #ifdef USE_HCACHE
-header_cache_t* imap_hcache_open (IMAP_DATA* idata, const char* path);
+int imap_hcache_open (IMAP_DATA* idata);
+void imap_hcache_close (IMAP_DATA* idata);
 HEADER* imap_hcache_get (IMAP_DATA* idata, unsigned int uid);
 int imap_hcache_put (IMAP_DATA* idata, HEADER* h);
 int imap_hcache_del (IMAP_DATA* idata, unsigned int uid);
index 2b8f2c46c6fea7176869e0c6546c3e6cabb71f6d..d2fe9890db77280173dec4afa623f6b695f8b302 100644 (file)
@@ -119,6 +119,8 @@ int imap_read_headers (IMAP_DATA* idata, int msgbegin, int msgend)
   idata->newMailCount = 0;
 
 #if USE_HCACHE
+  imap_hcache_open (idata);
+
   if (idata->hcache && !msgbegin)
   {
     uid_validity = mutt_hcache_fetch_raw (idata->hcache, "/UIDVALIDITY", imap_hcache_keylen);
@@ -199,6 +201,7 @@ int imap_read_headers (IMAP_DATA* idata, int msgbegin, int msgend)
       {
         if (h.data)
           imap_free_header_data ((void**) (void*) &h.data);
+        imap_hcache_close (idata);
         fclose (fp);
         return -1;
       }
@@ -300,6 +303,9 @@ int imap_read_headers (IMAP_DATA* idata, int msgbegin, int msgend)
     {
       if (h.data)
         imap_free_header_data ((void**) (void*) &h.data);
+#if USE_HCACHE
+      imap_hcache_close (idata);
+#endif
       fclose (fp);
       return -1;
     }
@@ -329,6 +335,8 @@ int imap_read_headers (IMAP_DATA* idata, int msgbegin, int msgend)
   if (idata->uidnext > 1)
     mutt_hcache_store_raw (idata->hcache, "/UIDNEXT", &idata->uidnext,
                           sizeof (idata->uidnext), imap_hcache_keylen);
+
+  imap_hcache_close (idata);
 #endif /* USE_HCACHE */
 
   fclose(fp);
index c62414685006cd47d50169eadd3630e2caf53ef4..2a278704e666b718ea4a746d3ecabd8265fd1b8e 100644 (file)
@@ -71,21 +71,32 @@ int imap_expand_path (char* path, size_t len)
 }
 
 #ifdef USE_HCACHE
-header_cache_t* imap_hcache_open (IMAP_DATA* idata, const char* path)
+int imap_hcache_open (IMAP_DATA* idata)
 {
   IMAP_MBOX mx;
   ciss_url_t url;
   char cachepath[LONG_STRING];
 
-  if (imap_parse_path (path, &mx) < 0)
-    return NULL;
+  if (imap_parse_path (idata->ctx->path, &mx) < 0)
+    return -1;
 
   mutt_account_tourl (&idata->conn->account, &url);
   url.path = mx.mbox;
   url_ciss_tostring (&url, cachepath, sizeof (cachepath), 0);
   FREE (&mx.mbox);
 
-  return mutt_hcache_open (HeaderCache, cachepath);
+  idata->hcache = mutt_hcache_open (HeaderCache, cachepath);
+
+  return idata->hcache != NULL ? 0 : -1;
+}
+
+void imap_hcache_close (IMAP_DATA* idata)
+{
+  if (!idata->hcache)
+    return;
+
+  mutt_hcache_close (idata->hcache);
+  idata->hcache = NULL;
 }
 
 HEADER* imap_hcache_get (IMAP_DATA* idata, unsigned int uid)