Hi, The follow-up patch to fix this was pushed to master today: commit abe191ed272c85f7bceb121aefeb8d8f4c7a9ed4 Author: Balazs Scheidler <bazsi@balabit.hu> Date: Thu Jul 14 12:28:12 2011 +0200 nvtable: fixed locking of the nv_register hash table. Signed-off-by: Balazs Scheidler <bazsi@balabit.hu> On Sat, 2011-05-28 at 15:56 +0200, Balazs Scheidler wrote:
Hi,
This locking is certainly necessary, however the scope is not enough in nv_registry_alloc_handle(). The lookup must also be locked, since the same name can be associated to a different value otherwise.
It should also be checked if this would happen on a fastpath though.
On Mon, 2011-05-23 at 11:56 +0200, Gergely Nagy wrote:
From: Juhasz Viktor <jviktor@balabit.hu>
Since nv_registry_alloc_handle() can be indirectly called from multiple threads, when it modifies the registry, that needs to be protected with a mutex.
Same goes for nv_registry_add_alias().
Signed-off-by: Viktor Juhasz <jviktor@balabit.hu> --- lib/nvtable.c | 6 ++++++ 1 files changed, 6 insertions(+), 0 deletions(-)
diff --git a/lib/nvtable.c b/lib/nvtable.c index aa9d8a1..d0a35d3 100644 --- a/lib/nvtable.c +++ b/lib/nvtable.c @@ -27,6 +27,8 @@ #include <string.h> #include <stdlib.h>
+GStaticMutex nv_registry_lock = G_STATIC_MUTEX_INIT; + const gchar *null_string = "";
NVHandle @@ -78,8 +80,10 @@ nv_registry_alloc_handle(NVRegistry *self, const gchar *name) stored.flags = 0; stored.name_len = len; stored.name = g_strdup(name); + g_static_mutex_lock(&nv_registry_lock); g_array_append_val(self->names, stored); g_hash_table_insert(self->name_map, stored.name, GUINT_TO_POINTER(self->names->len)); + g_static_mutex_unlock(&nv_registry_lock); return self->names->len; }
@@ -91,7 +95,9 @@ nv_registry_alloc_handle(NVRegistry *self, const gchar *name) void nv_registry_add_alias(NVRegistry *self, NVHandle handle, const gchar *alias) { + g_static_mutex_lock(&nv_registry_lock); g_hash_table_insert(self->name_map, (gchar *) alias, GUINT_TO_POINTER((glong) handle)); + g_static_mutex_unlock(&nv_registry_lock); }
void
-- Bazsi