Apply mutex when access connected application list. 44/288344/4 accepted/tizen/unified/20230227.042008
authorhj kim <backto.kim@samsung.com>
Wed, 15 Feb 2023 09:28:39 +0000 (18:28 +0900)
committerhj kim <backto.kim@samsung.com>
Thu, 16 Feb 2023 07:25:50 +0000 (16:25 +0900)
aul_listen_app_dead_signal() is called in the main thread, and try to acess connected application list.
it can cause a problem.

Change-Id: Ia637c5f4440f25214866e922974e818fc54c9e25

packaging/capi-media-controller.spec
svc/media_controller_svc.c

index 6138f60..df53098 100644 (file)
@@ -1,6 +1,6 @@
 Name:       capi-media-controller
 Summary:    A media controller library in Tizen Native API
-Version:    0.2.33
+Version:    0.2.34
 Release:    1
 Group:      Multimedia/API
 License:    Apache-2.0
index 46fba54..4fe9cca 100644 (file)
@@ -33,6 +33,7 @@ static GMainLoop *g_mc_svc_mainloop = NULL;
 static int g_connection_cnt = -1;
 static GList *g_connected_apps;
 static GSource *g_source;
+static GMutex g_connected_apps_mutex;
 
 typedef struct {
        int client_sock;
@@ -114,11 +115,15 @@ static void __mc_destroy_connected_apps(gpointer data)
 
 static void __mc_clean_connected_apps(void)
 {
+       g_mutex_lock(&g_connected_apps_mutex);
+
        if (g_connected_apps) {
                g_list_free_full(g_connected_apps, __mc_destroy_connected_apps);
 
                g_connected_apps = NULL;
        }
+
+       g_mutex_unlock(&g_connected_apps_mutex);
 }
 
 static void __mc_add_cmd_to_send(gpointer data, gpointer user_data)
@@ -479,8 +484,12 @@ static void __mc_destroy_connected_apps_after_noti(gpointer data)
 static int __mc_service_app_dead_handler(int pid, void *data)
 {
        GList *found_app = NULL;
+       g_autoptr(GMutexLocker) locker = NULL;
 
        mc_info("Received app_dead signal (pid : %d)", pid);
+
+       locker = g_mutex_locker_new(&g_connected_apps_mutex);
+
        mc_retvm_if(!g_connected_apps, AUL_R_OK, "No connected application!");
 
        while ((found_app = g_list_find_custom(g_connected_apps, (gconstpointer)GINT_TO_POINTER(pid),
@@ -558,7 +567,9 @@ static gboolean __mc_service_process(gpointer data)
 
        req = (mc_service_request *) g_queue_pop_head(request_queue);
 
+       g_mutex_lock(&g_connected_apps_mutex);
        msg = __process_msg(req->req_msg, &g_connected_apps);
+       g_mutex_unlock(&g_connected_apps_mutex);
 
        if (write(req->client_sock, &msg, sizeof(msg)) != sizeof(msg))
                mc_stderror("send failed");
@@ -697,6 +708,8 @@ gpointer mc_svc_thread(gpointer data)
 
        mc_debug_fenter();
 
+       g_mutex_init(&g_connected_apps_mutex);
+
        /* Get uid for login user */
        ret = __mc_sys_get_uid(&uid);
        if (ret < 0) {
@@ -784,6 +797,8 @@ gpointer mc_svc_thread(gpointer data)
 
        __mc_clean_connected_apps();
 
+       g_mutex_clear(&g_connected_apps_mutex);
+
        /* Free resources */
        g_io_channel_shutdown(channel, FALSE, NULL);
        g_io_channel_unref(channel);