btrfs-progs: cleanup after errors in open_file_or_dir3
authorDavid Sterba <dsterba@suse.cz>
Tue, 9 Jun 2015 13:24:51 +0000 (15:24 +0200)
committerDavid Sterba <dsterba@suse.cz>
Tue, 9 Jun 2015 13:24:51 +0000 (15:24 +0200)
We should zero the dirstream in case we close it ourselves, so the
caller does not do it again. Most current callers do not do that and
exit immediatelly.

Signed-off-by: David Sterba <dsterba@suse.cz>
utils.c

diff --git a/utils.c b/utils.c
index 1783737..41a04bd 100644 (file)
--- a/utils.c
+++ b/utils.c
@@ -1915,8 +1915,10 @@ int open_file_or_dir3(const char *fname, DIR **dirstream, int open_flags)
        }
        if (fd < 0) {
                fd = -1;
-               if (*dirstream)
+               if (*dirstream) {
                        closedir(*dirstream);
+                       *dirstream = NULL;
+               }
        }
        return fd;
 }