Skip to content

Commit

Permalink
lib-index: Fix duplicate fields in mail_cache_register_fields()
Browse files Browse the repository at this point in the history
Broken by hash_table_insert() API change. The earlier code was also a bit
wrong by allocating a bit too much memory when there were duplicate fields
being registered.
  • Loading branch information
sirainen committed Jun 3, 2016
1 parent 379b166 commit f27c7e6
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/lib-index/mail-cache-fields.c
Expand Up @@ -105,7 +105,7 @@ void mail_cache_register_fields(struct mail_cache *cache,
char *name;
void *value;
unsigned int new_idx;
unsigned int i, j;
unsigned int i, j, registered_count;

new_idx = cache->fields_count;
for (i = 0; i < fields_count; i++) {
Expand Down Expand Up @@ -141,10 +141,11 @@ void mail_cache_register_fields(struct mail_cache *cache,
cache->fields_count * sizeof(*cache->field_file_map),
new_idx * sizeof(*cache->field_file_map));

registered_count = cache->fields_count;
for (i = 0; i < fields_count; i++) {
unsigned int idx = fields[i].idx;

if (idx < cache->fields_count)
if (idx < registered_count)
continue;

/* new index - save it */
Expand All @@ -159,7 +160,9 @@ void mail_cache_register_fields(struct mail_cache *cache,

hash_table_insert(cache->field_name_hash, name,
POINTER_CAST(idx));
registered_count++;
}
i_assert(registered_count == new_idx);
cache->fields_count = new_idx;
}

Expand Down

0 comments on commit f27c7e6

Please sign in to comment.