lib: resource-monitor: Fix missing mutual exclusion
authorDongwoo Lee <dwoo08.lee@samsung.com>
Thu, 7 Mar 2024 06:41:29 +0000 (15:41 +0900)
committerDongwoo Lee <dwoo08.lee@samsung.com>
Thu, 7 Mar 2024 06:41:29 +0000 (15:41 +0900)
Since find_client_by_id() walks g_pass_resource_monitor_client_head
list which is prevented by critical section, it should be mutually
exclusive, thus mutex lock/unlock is added to former/later of loop.

Change-Id: I6ea2dad42ff9dd08dec331db7ea4c9de550da618
Signed-off-by: Dongwoo Lee <dwoo08.lee@samsung.com>
lib/resource-monitor/resource-monitor.c

index 75bff2249bffec674c81362badfad6efc575866d..89d2d247066a13af5d10094337c61e447b3a4f2f 100644 (file)
@@ -89,6 +89,7 @@ static struct pass_resource_monitor_client *find_client_by_id(int id)
        struct pass_resource_monitor_client *client;
        GList *node;
 
+       g_mutex_lock(&g_mutex);
        for (node = g_pass_resource_monitor_client_head;
                        node != NULL;
                        node = node->next) {
@@ -96,6 +97,7 @@ static struct pass_resource_monitor_client *find_client_by_id(int id)
                if (client->id == id)
                        return client;
        }
+       g_mutex_unlock(&g_mutex);
 
        return NULL;
 }