[Mesa-dev] [PATCH 3/4] mesa: NULL check the pointer before trying to dereference it

Ian Romanick idr at freedesktop.org
Tue Apr 9 16:59:21 PDT 2013


From: Ian Romanick <ian.d.romanick at intel.com>

Duh.

Fixes issues identified by Klocwork analysis:

    Pointer 'table' returned from call to function 'calloc' at line 115
    may be NULL and will be dereferenced at line 117.

and

    Suspicious dereference of pointer 'table' before NULL check at line
    119.

Signed-off-by: Ian Romanick <ian.d.romanick at intel.com>
---
 src/mesa/main/hash.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/mesa/main/hash.c b/src/mesa/main/hash.c
index 8c763e2..9b9fff8 100644
--- a/src/mesa/main/hash.c
+++ b/src/mesa/main/hash.c
@@ -114,9 +114,9 @@ _mesa_NewHashTable(void)
 {
    struct _mesa_HashTable *table = CALLOC_STRUCT(_mesa_HashTable);
 
-   table->ht = _mesa_hash_table_create(NULL, uint_key_compare);
-   _mesa_hash_table_set_deleted_key(table->ht, uint_key(DELETED_KEY_VALUE));
    if (table) {
+      table->ht = _mesa_hash_table_create(NULL, uint_key_compare);
+      _mesa_hash_table_set_deleted_key(table->ht, uint_key(DELETED_KEY_VALUE));
       _glthread_INIT_MUTEX(table->Mutex);
       _glthread_INIT_MUTEX(table->WalkMutex);
    }
-- 
1.8.1.4



More information about the mesa-dev mailing list