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

Showing the changes to kernel (1 of 1 file). Show all

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
1847 }1847 }
1848 1848
1849 /* Assert single root without parent */1849 /* 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);
1851 return -EINVAL;1852 return -EINVAL;
1853 }
1852 1854
1853 for (; i >= start_lvl; i--) {1855 for (; i >= start_lvl; i--) {
1854 group = stack[i];1856 group = stack[i];