[syslog-ng] [Bug 269] some code doesn't follow glib recomendations

bugzilla at bugzilla.balabit.com bugzilla at bugzilla.balabit.com
Fri Jan 31 14:08:43 CET 2014


https://bugzilla.balabit.com/show_bug.cgi?id=269





--- Comment #3 from Balazs Scheidler <bazsi at balabit.hu>  2014-01-31 14:08:43 ---
what about this patch instead? it delegates the freeing of the key to GHashTable and avoids having to store aliases in a separate array.

the unit test seems to run fine, but I didn't do very thorough testing/review. feedback is appreciated.


diff --git a/lib/nvtable.c b/lib/nvtable.c
index 504bebb..8462f76 100644
--- a/lib/nvtable.c
+++ b/lib/nvtable.c
@@ -102,7 +102,7 @@ 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_hash_table_insert(self->name_map, g_strdup(alias), GUINT_TO_POINTER((glong) handle));
   g_static_mutex_unlock(&nv_registry_lock);
 }

@@ -124,7 +124,7 @@ nv_registry_new(const gchar **static_names)
   NVRegistry *self = g_new0(NVRegistry, 1);
   gint i;

-  self->name_map = g_hash_table_new_full(g_str_hash, g_str_equal, NULL, NULL);
+  self->name_map = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, NULL);
   self->names = g_array_new(FALSE, FALSE, sizeof(NVHandleDesc));
   for (i = 0; static_names[i]; i++)
     {
@@ -136,10 +136,6 @@ nv_registry_new(const gchar **static_names)
 void
 nv_registry_free(NVRegistry *self)
 {
-  gint i;
-
-  for (i = 0; i < self->names->len; i++)
-    g_free(g_array_index(self->names, NVHandleDesc, i).name);
   g_array_free(self->names, TRUE);
   g_hash_table_destroy(self->name_map);
   g_free(self);


-- 
Configure bugmail: https://bugzilla.balabit.com/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are watching all bug changes.


More information about the syslog-ng mailing list