From df7d01ba61af4b516c1497bdb6702665b64e11a1 Mon Sep 17 00:00:00 2001 From: Timo Kokkonen Date: Mon, 7 Nov 2011 18:24:50 +0200 Subject: [PATCH] update_kpageflags: Ensure file descriptors are closed correctly on error If only opening only other of the files fails, the successfully opened file was not closed. This scenario is extremely unlikely, but should be fixed never the less. Signed-off-by: Timo Kokkonen --- parse.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/parse.c b/parse.c index c87a153..671ec50 100644 --- a/parse.c +++ b/parse.c @@ -416,9 +416,11 @@ int update_kpageflags(struct rb_root *root) int ret; kpageflags_fd = open("/proc/kpageflags", O_RDONLY); - kpagecount_fd = open("/proc/kpagecount", O_RDONLY); + if (kpageflags_fd < 0) + return -1; - if (kpageflags_fd == -1 || kpagecount_fd == -1) + kpagecount_fd = open("/proc/kpagecount", O_RDONLY); + if (kpagecount_fd < 0) return -1; pf = rb_to_pageframe(rb_first(root)); -- 2.44.0