-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)
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++)
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
}
}
-#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);
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");
return 0;
fail:
+#ifdef USE_HCACHE
+ mutt_hcache_close (idata->hcache);
+#endif
if (idata->state == IMAP_SELECTED)
idata->state = IMAP_AUTHENTICATED;
fail_noidata:
int n;
int rc;
#if USE_HCACHE
- void* hc = NULL;
char uidbuf[32];
#endif
}
}
-#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++)
{
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)
rc = 0;
out:
-#if USE_HCACHE
- mutt_hcache_close (hc);
-#endif
if (cmd.data)
FREE (&cmd.data);
if (appendctx)
}
}
+#ifdef USE_HCACHE
+ mutt_hcache_close (idata->hcache);
+#endif
mutt_bcache_close (&idata->bcache);
return 0;
#include "mutt_curses.h"
#include "mutt_socket.h"
#include "bcache.h"
+#ifdef USE_HCACHE
+#include "hcache.h"
+#endif
/* -- symbols -- */
#define IMAP_PORT 143
/* 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 :( */
/* 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);
progress_t progress;
#if USE_HCACHE
- header_cache_t *hc = NULL;
unsigned int *uid_validity = NULL;
unsigned int *uidnext = NULL;
int evalhc = 0;
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;
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)
{
if (h.data)
imap_free_header_data ((void**) &h.data);
fclose (fp);
- mutt_hcache_close (hc);
return -1;
}
}
#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++;
if (h.data)
imap_free_header_data ((void**) &h.data);
fclose (fp);
-#if USE_HCACHE
- mutt_hcache_close (hc);
-#endif /* USE_HCACHE */
return -1;
}
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)
{
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);
}
#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;