From: Timo Kokkonen Date: Mon, 7 Nov 2011 16:24:50 +0000 (+0200) Subject: update_kpageflags: Ensure file descriptors are closed correctly on error X-Git-Url: http://git.itanic.dy.fi/?p=scan-pagemap;a=commitdiff_plain;h=df7d01ba61af4b516c1497bdb6702665b64e11a1 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 --- 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));