]> git.itanic.dy.fi Git - scan-pagemap/commitdiff
update_kpageflags: Ensure file descriptors are closed correctly on error
authorTimo Kokkonen <kaapeli@itanic.dy.fi>
Mon, 7 Nov 2011 16:24:50 +0000 (18:24 +0200)
committerTimo Kokkonen <kaapeli@itanic.dy.fi>
Mon, 7 Nov 2011 16:30:09 +0000 (18:30 +0200)
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 <kaapeli@itanic.dy.fi>
parse.c

diff --git a/parse.c b/parse.c
index c87a15300ef7cc1346fd225ff39f6cf31dad95d6..671ec507f996d75496cb3db4f8f66aa92d371104 100644 (file)
--- 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));