logging: Remove useless code which causes bug 99/306599/5
authorUnsung Lee <unsung.lee@samsung.com>
Thu, 22 Feb 2024 08:41:24 +0000 (17:41 +0900)
committerUnsung Lee <unsung.lee@samsung.com>
Tue, 5 Mar 2024 12:07:31 +0000 (21:07 +0900)
Remove useless code which access critical section without lock.
g_queue_foreach() and g_queue_get_length() already handles empty queue case.

This problem is reported in coverity with 1739919 id.

Change-Id: Id7f678b5731d4339a61848c91251305e3050ff7c
Signed-off-by: Unsung Lee <unsung.lee@samsung.com>
src/resource-monitor/logging.c

index f487752..0d29712 100644 (file)
@@ -905,11 +905,9 @@ int logging_read_foreach(char *name, char *appid, char *pkgid,
        }
 
        /* search from cache */
-       if (!g_queue_is_empty(module->cache)) {
-               pthread_mutex_lock(&(module->cache_mutex));
-               g_queue_foreach(module->cache, (GFunc)logging_cache_search, (gpointer)&search);
-               pthread_mutex_unlock(&(module->cache_mutex));
-       }
+       pthread_mutex_lock(&(module->cache_mutex));
+       g_queue_foreach(module->cache, (GFunc)logging_cache_search, (gpointer)&search);
+       pthread_mutex_unlock(&(module->cache_mutex));
 
        return RESOURCED_ERROR_NONE;
 }
@@ -1042,16 +1040,14 @@ int logging_modify_appid(char *module_name, char *old_appid, char *new_appid, in
        }
 
        /* Modify cache */
-       if (!g_queue_is_empty(module->cache)) {
-               pthread_mutex_lock(&(module->cache_mutex));
-               for (i = 0; i < g_queue_get_length(module->cache); i++) {
-                       entry = (struct logging_table_form *)g_queue_peek_nth(
-                                       module->cache, i);
-                       if (entry->uid == uid && !strncmp(entry->appid, old_appid, strlen(old_appid)))
-                               snprintf(entry->appid, MAX_APPID_LENGTH, "%s", new_appid);
-               }
-               pthread_mutex_unlock(&(module->cache_mutex));
+       pthread_mutex_lock(&(module->cache_mutex));
+       for (i = 0; i < g_queue_get_length(module->cache); i++) {
+               entry = (struct logging_table_form *)g_queue_peek_nth(
+                               module->cache, i);
+               if (entry->uid == uid && !strncmp(entry->appid, old_appid, strlen(old_appid)))
+                       snprintf(entry->appid, MAX_APPID_LENGTH, "%s", new_appid);
        }
+       pthread_mutex_unlock(&(module->cache_mutex));
 
        /* Modify DB */
        switch (module->db_type) {