]> git.openfabrics.org - ~shefty/librdmacm.git/commitdiff
indexer: Free index_map resources when cleared
authorSean Hefty <sean.hefty@intel.com>
Thu, 22 May 2014 23:13:08 +0000 (16:13 -0700)
committerSean Hefty <sean.hefty@intel.com>
Thu, 22 May 2014 23:13:08 +0000 (16:13 -0700)
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>
src/indexer.c
src/indexer.h

index c8e8bce53ced2ab59c7ac25b8514c03f78951751..b9e400b58fc4e4aa1122f3c58051c5951d42ca8d 100644 (file)
@@ -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;
 }
index 0c5f3882673f696b4b36ee87b6325aa9095bbba7..fc8eae248c123c199c7d27deff71be08590b24ff 100644 (file)
@@ -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);