if (!data || !crc_matches(data, h->crc))
{
- FREE(&data);
+ mutt_hcache_free (&data);
return NULL;
}
(mdb_get (h->txn, h->db, &key, &data) != MDB_SUCCESS))
return NULL;
- /* Unlike other dbs, LMDB claims ownership of the returned data */
- char *d = safe_malloc (data.mv_size);
- memcpy (d, data.mv_data, data.mv_size);
- return d;
+ /* LMDB claims ownership of the returned data, so this will not be
+ * freed in mutt_hcache_free(). */
+ return data.mv_data;
#endif
}
}
}
+void mutt_hcache_free (void **data)
+{
+ if (!data || !*data)
+ return;
+
+#if HAVE_KC
+ kcfree (*data);
+ *data = NULL;
+#elif HAVE_LMDB
+ /* LMDB owns the data returned. It should not be freed */
+#else
+ FREE (data); /* __FREE_CHECKED__ */
+#endif
+}
+
#if HAVE_DB4
const char *mutt_hcache_backend (void)
{
void *mutt_hcache_fetch(header_cache_t *h, const char *filename, size_t (*keylen)(const char *fn));
void *mutt_hcache_fetch_raw (header_cache_t *h, const char *filename,
size_t (*keylen)(const char *fn));
+void mutt_hcache_free (void **data);
typedef enum {
MUTT_GENERATE_UIDVALIDITY = 1 /* use gettimeofday() as value */
{
uidvalidity = mutt_hcache_fetch_raw (hc, "/UIDVALIDITY", imap_hcache_keylen);
uidnext = mutt_hcache_fetch_raw (hc, "/UIDNEXT", imap_hcache_keylen);
- mutt_hcache_close (hc);
if (uidvalidity)
{
if (!status)
{
- FREE (&uidvalidity);
- FREE (&uidnext);
+ mutt_hcache_free ((void **)&uidvalidity);
+ mutt_hcache_free ((void **)&uidnext);
+ mutt_hcache_close (hc);
return imap_mboxcache_get (idata, mbox, 1);
}
status->uidvalidity = *uidvalidity;
dprint (3, (debugfile, "mboxcache: hcache uidvalidity %d, uidnext %d\n",
status->uidvalidity, status->uidnext));
}
- FREE (&uidvalidity);
- FREE (&uidnext);
+ mutt_hcache_free ((void **)&uidvalidity);
+ mutt_hcache_free ((void **)&uidnext);
+ mutt_hcache_close (hc);
}
#endif
if (puidnext)
{
uidnext = *puidnext;
- FREE (&puidnext);
+ mutt_hcache_free ((void **)&puidnext);
}
if (uid_validity && uidnext && *uid_validity == idata->uid_validity)
evalhc = 1;
- FREE (&uid_validity);
+ mutt_hcache_free ((void **)&uid_validity);
}
if (evalhc)
{
h = mutt_hcache_restore ((unsigned char*)uv, NULL);
else
dprint (3, (debugfile, "hcache uidvalidity mismatch: %u", *uv));
- FREE (&uv);
+ mutt_hcache_free ((void **)&uv);
}
return h;
mutt_free_header (&p->h);
#if USE_HCACHE
}
- FREE (&data);
+ mutt_hcache_free (&data);
#endif
last = p;
}
mutt_hcache_store (hc, ctx->hdrs[i]->data, ctx->hdrs[i], 0, strlen, MUTT_GENERATE_UIDVALIDITY);
}
- FREE(&data);
+ mutt_hcache_free (&data);
#endif
/*