[PATCH] perf sched: Fix resource leak in enable_sched_schedstats()

From: liujing

Date: Thu Sep 03 2026 - 04:34:00 EST


From: Liu Jing <liujing@xxxxxxxxxxxxxxxxxxxx>

In enable_sched_schedstats(), the FILE pointer fp is only closed when
ch == '0'. If ch is not '0' (i.e., sched_schedstats is already enabled),
the function returns 0 without calling fclose(fp), causing a resource
leak.

Fix it by adding fclose(fp) before the return statement.

Signed-off-by: Liu Jing <liujing@xxxxxxxxxxxxxxxxxxxx>
---
--- a/tools/perf/builtin-sched.c
+++ b/tools/perf/builtin-sched.c
@@ -4114,8 +4114,8 @@
*reset = 1;
rewind(fp);
putc('1', fp);
- fclose(fp);
- }
+ }
+ fclose(fp);
return 0;
}