Free the key of g_hash_table normally using g_hash_table_foreach_remove 48/87248/5
authorYoungHun Kim <yh8004.kim@samsung.com>
Wed, 7 Sep 2016 06:52:28 +0000 (15:52 +0900)
committerYoungHun Kim <yh8004.kim@samsung.com>
Mon, 19 Sep 2016 23:37:16 +0000 (16:37 -0700)
Change-Id: I50385e911cec8f9f5710342b586f34219450df6d

packaging/mused.spec
src/muse_core_ipc.c
src/muse_core_module.c

index 00507de..975262c 100644 (file)
@@ -1,6 +1,6 @@
 Name:       mused
 Summary:    A Multimedia Daemon in Tizen Native API
-Version:    0.1.7
+Version:    0.1.8
 Release:    1
 Group:      System/Libraries
 License:    Apache-2.0
index a80b2cb..fbdf11f 100644 (file)
@@ -54,7 +54,7 @@ static muse_recv_data_t *_muse_core_ipc_new_qdata(char **recvBuff, int recvSize,
 static bool _muse_core_ipc_msg_complete_confirm(muse_client_h client, char *msg, int msg_len);
 static bool _muse_core_ipc_init_bufmgr(void);
 static void _muse_core_ipc_deinit_bufmgr(void);
-static void _muse_core_ipc_client_free(gpointer key, gpointer value, gpointer user_data);
+static gboolean _muse_core_ipc_free_key(gpointer key, gpointer value, gpointer user_data);
 static void _muse_core_ipc_free(void);
 static void _muse_core_ipc_init_instance(void (*free)(void));
 static int _muse_core_ipc_check_fd(int fd);
@@ -64,7 +64,7 @@ static void _muse_core_ipc_client_cleanup(muse_module_h module)
        g_return_if_fail(module != NULL);
 
        muse_core_log_get_instance()->flush_msg();
-       g_hash_table_foreach(g_muse_core_ipc->client_table, (GHFunc)_muse_core_ipc_client_free, NULL);
+       g_hash_table_foreach_remove(g_muse_core_ipc->client_table, _muse_core_ipc_free_key, NULL);
 
        g_queue_free(module->ch[MUSE_CHANNEL_DATA].queue);
        module->ch[MUSE_CHANNEL_DATA].queue = NULL;
@@ -342,9 +342,10 @@ static void _muse_core_ipc_client_new(int sock_fd, muse_client_h client)
        g_hash_table_insert(g_muse_core_ipc->client_table, g_muse_core_ipc->key, (gpointer)client);
 }
 
-static void _muse_core_ipc_client_free(gpointer key, gpointer value, gpointer user_data)
+static gboolean _muse_core_ipc_free_key(gpointer key, gpointer value, gpointer user_data)
 {
-       g_hash_table_remove(g_muse_core_ipc->client_table, key);
+       g_free(key);
+       return TRUE;
 }
 
 static void _muse_core_ipc_free(void)
index 68e259f..7b3fdf0 100644 (file)
@@ -30,6 +30,7 @@ static muse_core_module_t *g_muse_core_module = NULL;
 static GModule *_muse_core_module_load(int api_module);
 static void _muse_core_module_dispatch(int cmd, muse_module_h module);
 static gboolean _muse_core_module_close(muse_module_h module);
+static gboolean _muse_core_module_free_key(gpointer key, gpointer value, gpointer user_data);
 static void _muse_core_module_free(void);
 static GModule *_muse_core_module_get_dllsymbol(int api_module);
 static void _muse_core_module_set_dllsymbol_loaded_value(int api_module, GModule *module, gboolean value);
@@ -135,6 +136,12 @@ static int _muse_core_module_get_dllsymbol_value(int api_module, const char *key
        }
 }
 
+static gboolean _muse_core_module_free_key(gpointer key, gpointer value, gpointer user_data)
+{
+       g_free(key);
+       return TRUE;
+}
+
 static void _muse_core_module_free(void)
 {
        int idx = 0;
@@ -143,6 +150,7 @@ static void _muse_core_module_free(void)
 
        for (idx = 0; idx < MUSE_MODULE_MAX; idx++) {
                g_module_close(g_muse_core_module->module[idx]);
+               g_hash_table_foreach_remove(g_muse_core_module->table[idx], _muse_core_module_free_key, NULL);
                g_hash_table_destroy(g_muse_core_module->table[idx]);
        }