Upate the creation of module table with g_hash_table_new_full 67/173467/1
authorYoungHun Kim <yh8004.kim@samsung.com>
Thu, 22 Mar 2018 01:07:06 +0000 (10:07 +0900)
committerYoungHun Kim <yh8004.kim@samsung.com>
Thu, 22 Mar 2018 01:07:08 +0000 (10:07 +0900)
Change-Id: Ic365cfd71e734d2c94fcf8bc57c657758f5a2f69

server/src/muse_server_module.c

index a749be3..0a17527 100644 (file)
@@ -25,7 +25,6 @@ static GMutex dllsym_table_lock;
 
 static gboolean _ms_module_dispatch_timeout_callback(gpointer data);
 static gboolean _ms_module_enable_dispatch_timeout_callback(int cmd, muse_module_h m);
-static gboolean _ms_module_free_key(gpointer key, gpointer value, gpointer user_data);
 static void _ms_module_set_loaded_dllsym(int idx, GModule *dllsym, gboolean value);
 
 static gboolean _ms_module_dispatch_timeout_callback(gpointer data)
@@ -76,12 +75,6 @@ static void _ms_module_set_loaded_dllsym(int idx, GModule *dllsym, gboolean valu
        SECURE_LOGD("dll_handle: %p", module->dllsym);
 }
 
-static gboolean _ms_module_free_key(gpointer key, gpointer value, gpointer user_data)
-{
-       MUSE_G_FREE(key);
-       return TRUE;
-}
-
 GModule *ms_module_open(int idx)
 {
        GModule *dllsym = NULL;
@@ -212,24 +205,13 @@ gboolean ms_module_get_loaded_dllsym(int idx)
 
 void ms_module_set_dllsym_value(int idx, const char *name, gpointer value)
 {
-       gpointer orig_key;
        ms_module_t *module = ms_get_module_instance(idx);
 
        g_return_if_fail(module);
        g_return_if_fail(name);
 
        g_mutex_lock(&dllsym_table_lock);
-
-       /* Try looking up this key. */
-       if (g_hash_table_lookup_extended(module->dllsym_table, name, &orig_key, NULL)) {
-               g_hash_table_remove(module->dllsym_table, name);
-               g_hash_table_insert(module->dllsym_table, g_strdup(name), value);
-               g_free(orig_key);
-       } else {
-               /* Insert into our hash table it is not a duplicate. */
-               g_hash_table_insert(module->dllsym_table, g_strdup(name), value);
-       }
-
+       g_hash_table_insert(module->dllsym_table, g_strdup(name), value);
        g_mutex_unlock(&dllsym_table_lock);
 }
 
@@ -276,7 +258,6 @@ void ms_module_deinit(ms_module_t *module)
 
        g_mutex_clear(&module->lock);
        g_module_close(module->dllsym);
-       g_hash_table_foreach_remove(module->dllsym_table, _ms_module_free_key, NULL);
        g_hash_table_destroy(module->dllsym_table);
 
        free(module);
@@ -292,7 +273,7 @@ void ms_module_init(ms_module_t *module)
 
        g_mutex_init(&module->lock);
        module->loaded = FALSE;
-       module->dllsym_table = g_hash_table_new(g_str_hash, g_str_equal);
+       module->dllsym_table = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, NULL);
        g_return_if_fail(module->dllsym_table);
        for (disp_idx = 0; disp_idx < MUSE_DISPATCHER_MAX; disp_idx++)
                ms_module_set_timeout(module->idx, disp_idx, ms_get_instance()->conf->host_infos[module->idx]->timeout);