cpu-boosting: Fix a bug of memory leak 48/319348/1
authorUnsung Lee <unsung.lee@samsung.com>
Sun, 9 Feb 2025 12:33:08 +0000 (21:33 +0900)
committerUnsung Lee <unsung.lee@samsung.com>
Sun, 9 Feb 2025 12:38:59 +0000 (21:38 +0900)
Fix a bug causing memory leak due to incorrect hash table access.
g_hash_table_remove() decreases ref_cnt of syscommon_resourced_cpu_boosting_info.
Previously, hash table index was wrong and ref_cnt was not decreased.

Change-Id: I22604e685a655ed2491c21a727626a1bb57fa675
Signed-off-by: Unsung Lee <unsung.lee@samsung.com>
src/resource-optimizer/cpu/cpu-boosting.c

index feca06de39b850ca337cfe6c37e5ddd41d73c866..19d7d39d27c1b0dd2bc139223fa7b38b01207e49 100644 (file)
@@ -1034,6 +1034,8 @@ static void cpu_boosting_find_and_insert_info(pid_t tid,
 
        /* Case2: Previous CPU boosting on the target thread, but different CPU boosting level */
        if (cpu_boosting_info->level != cpu_boosting_level) {
+               cpu_boosting_level_e prev_cpu_boosting_level = cpu_boosting_info->level;
+
                /**
                 * Do not free cpu_boosting_info in
                 * g_cpu_boosting_info_table[cpu_boosting_info->level].
@@ -1044,7 +1046,7 @@ static void cpu_boosting_find_and_insert_info(pid_t tid,
                set_cpu_boosting_info(cpu_boosting_info_set_flag, cpu_boosting_info,
                                tid, cpu_boosting_info->ref_cnt + 1, cpu_boosting_flags, timer_id, cpu_boosting_level);
 
-               g_hash_table_remove(g_cpu_boosting_info_table[cpu_boosting_info->level],
+               g_hash_table_remove(g_cpu_boosting_info_table[prev_cpu_boosting_level],
                                &cpu_boosting_info->tid);
                g_hash_table_insert(g_cpu_boosting_info_table[cpu_boosting_level],
                                &cpu_boosting_info->tid, cpu_boosting_info);