[Mesa-dev] [PATCH 09/13] mesa: Add missing null checks into prog_hash_table.c

Juha-Pekka Heikkila juhapekka.heikkila at gmail.com
Wed Mar 12 14:11:51 PDT 2014


Check calloc return values in hash_table_insert() and
hash_table_replace()

Signed-off-by: Juha-Pekka Heikkila <juhapekka.heikkila at gmail.com>
---
 src/mesa/program/prog_hash_table.c | 23 +++++++++++++++++------
 1 file changed, 17 insertions(+), 6 deletions(-)

diff --git a/src/mesa/program/prog_hash_table.c b/src/mesa/program/prog_hash_table.c
index f45ed46..617bdaa 100644
--- a/src/mesa/program/prog_hash_table.c
+++ b/src/mesa/program/prog_hash_table.c
@@ -143,10 +143,15 @@ hash_table_insert(struct hash_table *ht, void *data, const void *key)
 
     node = calloc(1, sizeof(*node));
 
-    node->data = data;
-    node->key = key;
+    if (node != NULL) {
+       node->data = data;
+       node->key = key;
 
-    insert_at_head(& ht->buckets[bucket], & node->link);
+       insert_at_head(& ht->buckets[bucket], & node->link);
+    }
+    else {
+       _mesa_error_no_memory(__FUNCTION__);
+    }
 }
 
 bool
@@ -168,10 +173,16 @@ hash_table_replace(struct hash_table *ht, void *data, const void *key)
 
     hn = calloc(1, sizeof(*hn));
 
-    hn->data = data;
-    hn->key = key;
+    if (hn != NULL) {
+       hn->data = data;
+       hn->key = key;
+
+       insert_at_head(& ht->buckets[bucket], & hn->link);
+    }
+    else {
+       _mesa_error_no_memory(__FUNCTION__);
+    }
 
-    insert_at_head(& ht->buckets[bucket], & hn->link);
     return false;
 }
 
-- 
1.8.1.2



More information about the mesa-dev mailing list