Free memory allocated for index map entries when they are no
longer in use. To handle this, count the number of entries
stored by the index map item arrays and release the arrays when
no items are being tracked.
This reduces valgrind noise.
Problem reported by: Hannes Weisbach <hannes_weisbach@gmx.net>
Signed-off-by: Sean Hefty <sean.hefty@intel.com>
entry = idm->array[idx_array_index(index)];
entry[idx_entry_index(index)] = item;
+ idm->count[idx_array_index(index)]++;
return index;
}
entry = idm->array[idx_array_index(index)];
item = entry[idx_entry_index(index)];
entry[idx_entry_index(index)] = NULL;
+ if (--idm->count[idx_array_index(index)] == 0) {
+ free(idm->array[idx_array_index(index)]);
+ idm->array[idx_array_index(index)] = NULL;
+ }
return item;
}
struct index_map
{
void **array[IDX_ARRAY_SIZE];
+ int count[IDX_ARRAY_SIZE];
};
int idm_set(struct index_map *idm, int index, void *item);