From a5c9d0a3f4c72eb59426b4b67fc7015ab5bed580 Mon Sep 17 00:00:00 2001 From: Joachim Nilsson Date: Mon, 6 Jan 2020 22:04:59 +0100 Subject: [PATCH] initctl: Fix file descriptor leak, found by Coverity Signed-off-by: Joachim Nilsson --- src/initctl.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/initctl.c b/src/initctl.c index 913bce16..3dc4dfa8 100644 --- a/src/initctl.c +++ b/src/initctl.c @@ -531,7 +531,7 @@ static int dump_cgroup(const char *fpath, const struct stat *sb, int tflag, stru group = strrchr(fpath, '/'); if (!group) - return 0; + goto err; group++; while (fgets(buf, sizeof(buf), fp)) { @@ -552,8 +552,9 @@ static int dump_cgroup(const char *fpath, const struct stat *sb, int tflag, stru printf("\n%c :- %d %s", user ? ' ' : '|', pid, buf); } - fclose(fp); +err: + fclose(fp); if (num) printf("\r%c\n", user ? ' ' : '|');