aboutsummaryrefslogtreecommitdiffstats
path: root/src/mesa/program/hash_table.c
diff options
context:
space:
mode:
authorAntoine Labour <[email protected]>2012-05-24 18:17:50 -0700
committerStéphane Marchesin <[email protected]>2012-06-12 14:42:22 -0700
commit3c9fab88226af8360817c01ecde38348284e6ce7 (patch)
tree18147c9d3a87fd1ade9ae1043d131e9ff7200baf /src/mesa/program/hash_table.c
parente2e9b4b10fcf3ba6358b9be54638f850523af82e (diff)
mesa: Fix hash table leak
When a value was replaced, the new key was strdup'd and leaked. To fix this, we modify the hash table implementation to return whether the value was replaced and free() the (now useless) duplicate string.
Diffstat (limited to 'src/mesa/program/hash_table.c')
-rw-r--r--src/mesa/program/hash_table.c5
1 files changed, 3 insertions, 2 deletions
diff --git a/src/mesa/program/hash_table.c b/src/mesa/program/hash_table.c
index dc8563a330f..7dabadc5058 100644
--- a/src/mesa/program/hash_table.c
+++ b/src/mesa/program/hash_table.c
@@ -149,7 +149,7 @@ hash_table_insert(struct hash_table *ht, void *data, const void *key)
insert_at_head(& ht->buckets[bucket], & node->link);
}
-void
+bool
hash_table_replace(struct hash_table *ht, void *data, const void *key)
{
const unsigned hash_value = (*ht->hash)(key);
@@ -162,7 +162,7 @@ hash_table_replace(struct hash_table *ht, void *data, const void *key)
if ((*ht->compare)(hn->key, key) == 0) {
hn->data = data;
- return;
+ return true;
}
}
@@ -172,6 +172,7 @@ hash_table_replace(struct hash_table *ht, void *data, const void *key)
hn->key = key;
insert_at_head(& ht->buckets[bucket], & hn->link);
+ return false;
}
void