Skip to contentSkip to conversation

indexer: Free index_map resources when cleared

PATCH New [email protected] 1 participant 1 message May 24, 2014 InfiniBand

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 indexer: Free index_map resources when cleared

From: Sean Hefty <[email protected]>

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 <[email protected]>

---
 src/indexer.c |    5 +++++
 src/indexer.h |    1 +
 2 files changed, 6 insertions(+), 0 deletions(-)
src/indexer.c +5 -0
index c8e8bce..b9e400b 100644
@@ -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;
 }
src/indexer.h +1 -0
index 0c5f388..fc8eae2 100644
@@ -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);
Signature · 6 lines
1.7.3

--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html