While reading through Kristian's EGLImage patches I came across some
questionable old code in the _mesa_HashLookup and _mesa_HashInsert
functions. The _mesa_HashLookup does a linked list chase down a
collision chain without holding a mutex. The _mesa_HashInsert does
a MALLOC_STRUCT without checking the result. Here are patches for
both of those. The _mesa_HashInsert fix is only half-hearted.
It checks for a malloc failure and returns without segment faulting.
But it has no return value. So it doesn't indicate to the caller
that the data was not inserted into the hash.
--
Mike Stroyan - Software Architect
LunarG, Inc. - The Graphics Experts
Cell: (970) 219-7905
Email: m...@lunarg.com
Website: http://www.lunarg.com
From 60aa1fc6754d942fe481bf40f57a40358dc2b20e Mon Sep 17 00:00:00 2001
From: Mike Stroyan <m...@lunarg.com>
Date: Mon, 15 Feb 2010 17:40:43 -0700
Subject: [PATCH 1/2] Lock mutex around _mesa_HashLookup linked list chase.
---
src/mesa/main/hash.c | 5 ++++-
1 files changed, 4 insertions(+), 1 deletions(-)
diff --git a/src/mesa/main/hash.c b/src/mesa/main/hash.c
index 08c6456..7666a4b 100644
--- a/src/mesa/main/hash.c
+++ b/src/mesa/main/hash.c
@@ -137,13 +137,16 @@ _mesa_HashLookup(const struct _mesa_HashTable *table, GLuint key)
assert(key);
pos = HASH_FUNC(key);
+ _glthread_LOCK_MUTEX(table->Mutex);
entry = table->Table[pos];
while (entry) {
if (entry->Key == key) {
- return entry->Data;
+ _glthread_UNLOCK_MUTEX(table->Mutex);
+ return entry->Data;
}
entry = entry->Next;
}
+ _glthread_UNLOCK_MUTEX(table->Mutex);
return NULL;
}
--
1.6.3.3
From 2082cf395a272b168bd3b9203df19cbb86ddc423 Mon Sep 17 00:00:00 2001
From: Mike Stroyan <m...@lunarg.com>
Date: Mon, 15 Feb 2010 17:43:33 -0700
Subject: [PATCH 2/2] Test for failed malloc in _mesa_HashInsert.
---
src/mesa/main/hash.c | 10 ++++++----
1 files changed, 6 insertions(+), 4 deletions(-)
diff --git a/src/mesa/main/hash.c b/src/mesa/main/hash.c
index 7666a4b..ae2f2fd 100644
--- a/src/mesa/main/hash.c
+++ b/src/mesa/main/hash.c
@@ -194,10 +194,12 @@ _mesa_HashInsert(struct _mesa_HashTable *table, GLuint key, void *data)
/* alloc and insert new table entry */
entry = MALLOC_STRUCT(HashEntry);
- entry->Key = key;
- entry->Data = data;
- entry->Next = table->Table[pos];
- table->Table[pos] = entry;
+ if (entry) {
+ entry->Key = key;
+ entry->Data = data;
+ entry->Next = table->Table[pos];
+ table->Table[pos] = entry;
+ }
_glthread_UNLOCK_MUTEX(table->Mutex);
}
--
1.6.3.3
------------------------------------------------------------------------------
SOLARIS 10 is the OS for Data Centers - provides features such as DTrace,
Predictive Self Healing and Award Winning ZFS. Get Solaris 10 NOW
http://p.sf.net/sfu/solaris-dev2dev
_______________________________________________
Mesa3d-dev mailing list
Mesa3d-dev@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mesa3d-dev