From af52c7550e646f797d78b148cd46d3faeb2678e7 Mon Sep 17 00:00:00 2001 From: Brendan Cully Date: Thu, 5 Apr 2007 17:33:47 -0700 Subject: [PATCH] Keep hcache pointer in idata, open and close with mailbox --- ChangeLog | 8 +++++++- imap/imap.c | 33 +++++++++++++-------------------- imap/imap_private.h | 8 +++++++- imap/message.c | 23 +++++++---------------- imap/util.c | 2 +- 5 files changed, 35 insertions(+), 39 deletions(-) diff --git a/ChangeLog b/ChangeLog index be4c1137..5a27e34d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,4 +1,10 @@ -2007-04-05 15:21 -0700 Brendan Cully (7cf4415ec23d) +2007-04-05 17:07 -0700 Brendan Cully (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) diff --git a/imap/imap.c b/imap/imap.c index ff939c1c..406221f3 100644 --- a/imap/imap.c +++ b/imap/imap.c @@ -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; diff --git a/imap/imap_private.h b/imap/imap_private.h index 9022482b..d7bde1d9 100644 --- a/imap/imap_private.h +++ b/imap/imap_private.h @@ -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); diff --git a/imap/message.c b/imap/message.c index 7a91b7f2..83d9b777 100644 --- a/imap/message.c +++ b/imap/message.c @@ -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); diff --git a/imap/util.c b/imap/util.c index 7fd0757a..9499c176 100644 --- a/imap/util.c +++ b/imap/util.c @@ -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; -- 2.40.0