Apply mutex when access connected application list. 93/289193/1
authorhj kim <backto.kim@samsung.com>
Wed, 15 Feb 2023 09:28:39 +0000 (18:28 +0900)
committerHaejeong kim <backto.kim@samsung.com>
Thu, 2 Mar 2023 09:02:38 +0000 (09:02 +0000)
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
(cherry picked from commit bc5712044cfeb30fa261d0e798ff230944c5b75c)

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

index 6138f60095a15b0d155f63f55fea0a246d5f8528..df530987b90e01aa88e4c29b01324949e58b81a1 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 26b01f13a90accabf8594cfed63080a624ea3c06..9a59c96852b99fb4ad129632df1bb03526b53b2d 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) {
@@ -787,6 +800,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);