Skip to contentSkip to conversation

timers/migration: Fix memory leak in tmigr_setup_groups()

PATCH New Zhan Xusheng 1 participant 1 message Mar 23 High-resolution timers, timer wheel, clockevents

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 timers/migration: Fix memory leak in tmigr_setup_groups()

tmigr_setup_groups() allocates 'stack' via kzalloc_objs(), but in the case where WARN_ON_ONCE(i >= tmigr_hierarchy_levels) triggers, the function returns -EINVAL without freeing 'stack', causing a memory leak.

Fix this by redirecting the error path to the common 'out:' label so that 'stack' is properly freed.

---
 kernel/time/timer_migration.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
kernel/time/timer_migration.c +4 -2
index 155eeaea4113..92bcf876630c 100644
@@ -1804,8 +1804,10 @@ static int tmigr_setup_groups(unsigned int cpu, unsigned int node,
 	}
 
 	/* Assert single root without parent */
-	if (WARN_ON_ONCE(i >= tmigr_hierarchy_levels))
-		return -EINVAL;
+	if (WARN_ON_ONCE(i >= tmigr_hierarchy_levels)) {
+		err = -EINVAL;
+		goto out;
+	}
 
 	for (; i >= start_lvl; i--) {
 		group = stack[i];
Signature · 1 line
2.43.0