From: Sean Hefty Date: Thu, 22 May 2014 23:13:08 +0000 (-0700) Subject: indexer: Free index_map resources when cleared X-Git-Tag: v1.0.19~25 X-Git-Url: https://openfabrics.org/gitweb/?a=commitdiff_plain;h=386b97e807917a8ca7f6d12d66e34dc9441f7502;p=~shefty%2Flibrdmacm.git indexer: Free index_map resources when cleared 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 Signed-off-by: Sean Hefty --- diff --git a/src/indexer.c b/src/indexer.c index c8e8bce5..b9e400b5 100644 --- a/src/indexer.c +++ b/src/indexer.c @@ -151,6 +151,7 @@ int idm_set(struct index_map *idm, int index, void *item) entry = idm->array[idx_array_index(index)]; entry[idx_entry_index(index)] = item; + idm->count[idx_array_index(index)]++; return index; } @@ -162,5 +163,9 @@ void *idm_clear(struct index_map *idm, int 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; } diff --git a/src/indexer.h b/src/indexer.h index 0c5f3882..fc8eae24 100644 --- a/src/indexer.h +++ b/src/indexer.h @@ -85,6 +85,7 @@ static inline void *idx_at(struct indexer *idx, int index) struct index_map { void **array[IDX_ARRAY_SIZE]; + int count[IDX_ARRAY_SIZE]; }; int idm_set(struct index_map *idm, int index, void *item);