const struct mail_cache_header *hdr;
const struct mail_cache_field *fields, *field;
unsigned int i, count, cache_idx;
+ pool_t pool;
(void)mail_cache_open_and_verify(cache);
if (MAIL_CACHE_IS_UNUSABLE(cache)) {
hdr->field_header_offset);
printf("-- Cache fields --\n");
- fields = mail_cache_register_get_list(cache, pool_datastack_create(),
- &count);
+ fields = mail_cache_register_get_list(cache, &pool, &count);
printf(
" # Name Type Size Dec Last used\n");
for (i = 0; i < cache->file_fields_count; i++) {
cache_decision2str(field->decision),
unixdate2str(field->last_used));
}
+ pool_unref(&pool);
}
static void dump_message_part(string_t *str, const struct message_part *part)
if (MAIL_CACHE_IS_UNUSABLE(src))
return 0; /* no caching decisions */
+ pool_t pool;
unsigned int count = 0;
struct mail_cache_field *fields =
- mail_cache_register_get_list(src, pool_datastack_create(), &count);
+ mail_cache_register_get_list(src, &pool, &count);
i_assert(fields != NULL || count == 0);
if (count > 0)
mail_cache_register_fields(dst, fields, count,
that the fields are updated even if the cache was already created
and no purging was done. */
dst->field_header_write_pending = TRUE;
+ pool_unref(&pool);
return mail_cache_purge(dst, 0, "copy cache decisions");
}
}
struct mail_cache_field *
-mail_cache_register_get_list(struct mail_cache *cache, pool_t pool,
+mail_cache_register_get_list(struct mail_cache *cache, pool_t *pool_r,
unsigned int *count_r)
{
struct mail_cache_field *list;
if (!cache->opened)
(void)mail_cache_open_and_verify(cache);
+ *pool_r = pool_alloconly_create("mail cache register fields", 1024);
list = cache->fields_count == 0 ? NULL :
- p_new(pool, struct mail_cache_field, cache->fields_count);
+ p_new(*pool_r, struct mail_cache_field, cache->fields_count);
for (i = 0; i < cache->fields_count; i++) {
list[i] = cache->fields[i].field;
- list[i].name = p_strdup(pool, list[i].name);
+ list[i].name = p_strdup(*pool_r, list[i].name);
}
*count_r = cache->fields_count;
/* Returns specified field */
const struct mail_cache_field *
mail_cache_register_get_field(struct mail_cache *cache, unsigned int field_idx);
-/* Returns a list of all registered fields */
+/* Returns a list of all registered fields. The returned pool must be freed. */
struct mail_cache_field *
-mail_cache_register_get_list(struct mail_cache *cache, pool_t pool,
+mail_cache_register_get_list(struct mail_cache *cache, pool_t *pool_r,
unsigned int *count_r);
/* Returns TRUE if cache should be purged. */
struct mail *_mail = &mail->mail.mail;
const struct mail_cache_field *all_cache_fields;
unsigned int i, count;
+ pool_t pool;
all_cache_fields =
- mail_cache_register_get_list(_mail->box->cache,
- pool_datastack_create(), &count);
+ mail_cache_register_get_list(_mail->box->cache, &pool, &count);
for (i = 0; i < count; i++) {
if (!str_begins_icase_with(all_cache_fields[i].name, "hdr."))
continue;
array_idx_set(&mail->header_match, all_cache_fields[i].idx,
&mail->header_match_value);
}
+ pool_unref(&pool);
}
void index_mail_parse_header_init(struct index_mail *mail,
ARRAY_TYPE(mailbox_cache_field) *cache_fields;
struct mailbox_cache_field *cf;
unsigned int i, count;
+ pool_t pool;
- fields = mail_cache_register_get_list(box->cache,
- pool_datastack_create(), &count);
+ fields = mail_cache_register_get_list(box->cache, &pool, &count);
cache_fields = t_new(ARRAY_TYPE(mailbox_cache_field), 1);
t_array_init(cache_fields, count);
dec = fields[i].decision & ENUM_NEGATE(MAIL_CACHE_DECISION_FORCED);
if (dec != MAIL_CACHE_DECISION_NO) {
cf = array_append_space(cache_fields);
- cf->name = fields[i].name;
+ cf->name = t_strdup(fields[i].name);
cf->decision = fields[i].decision;
cf->last_used = fields[i].last_used;
}
}
metadata_r->cache_fields = cache_fields;
+ pool_unref(&pool);
}
static void get_metadata_precache_fields(struct mailbox *box,
const struct mail_cache_field *fields;
unsigned int i, count;
enum mail_fetch_field cache = 0;
+ pool_t pool;
- fields = mail_cache_register_get_list(box->cache,
- pool_datastack_create(), &count);
+ fields = mail_cache_register_get_list(box->cache, &pool, &count);
for (i = 0; i < count; i++) {
const char *name = fields[i].name;
"Ignoring unknown cache field: %s", name);
}
metadata_r->precache_fields = cache;
+ pool_unref(&pool);
}
static int
const struct mail_cache_field *old_fields;
struct mail_cache_field field;
unsigned int i, j, old_count;
+ pool_t pool;
- old_fields = mail_cache_register_get_list(box->cache,
- pool_datastack_create(),
+ old_fields = mail_cache_register_get_list(box->cache, &pool,
&old_count);
/* There shouldn't be many fields, so don't worry about O(n^2). */
array_count(&new_fields),
unsafe_data_stack_pool);
}
+ pool_unref(&pool);
}
static int
enum mail_cache_decision_type dec, vsize_dec;
enum mail_fetch_field allowed_pop3_fields;
bool not_pop3_only = FALSE;
+ pool_t pool;
if (mail->pop3_state_set)
return mail->pop3_state;
} else {
/* also check if there are any non-[pv]size cached fields */
vsize_dec = MAIL_CACHE_DECISION_NO;
- fields = mail_cache_register_get_list(box->cache,
- pool_datastack_create(),
+ fields = mail_cache_register_get_list(box->cache, &pool,
&count);
for (i = 0; i < count; i++) {
dec = fields[i].decision & ENUM_NEGATE(MAIL_CACHE_DECISION_FORCED);
fields[i].idx != psize_idx)
not_pop3_only = TRUE;
}
+ pool_unref(&pool);
}
if (index_mail_get_vsize_extension(&mail->mail.mail) != NULL) {