History

timers/migration: Fix memory leak in tmigr_setup_groups() error path

When the WARN_ON_ONCE(i >= tmigr_hierarchy_levels) assertion triggers, the function returns -EINVAL without freeing the 'stack' memory allocated via kzalloc_objs() at the beginning of the function. Add kfree(stack) before returning to prevent the memory leak.

Malaya Kumar Rout committed 4 months ago

Commit eddfded1 parent f2eee7e1 file · +3 −1Browse files

Unified · Split

kernel/time/timer_migration.c+3−1
@@ -1847,8 +1847,10 @@ static int tmigr_setup_groups(struct tmigr_hierarchy *hier, unsigned int cpu, · 1846 unmodified lines
18471847 }
18481848
18491849 /* Assert single root without parent */
1850− if (WARN_ON_ONCE(i >= tmigr_hierarchy_levels))
1850+ if (WARN_ON_ONCE(i >= tmigr_hierarchy_levels)) {
1851+ kfree(stack);
18511852 return -EINVAL;
1853+ }
18521854
18531855 for (; i >= start_lvl; i--) {
18541856 group = stack[i];