Remember to close directories when we are finished with them.
authorNeil Brown <neilb@suse.de>
Mon, 26 May 2008 23:18:34 +0000 (09:18 +1000)
committerNeil Brown <neilb@suse.de>
Mon, 26 May 2008 23:18:34 +0000 (09:18 +1000)
sysfs.c
util.c

diff --git a/sysfs.c b/sysfs.c
index 87d314c..ea7d52f 100644 (file)
--- a/sysfs.c
+++ b/sysfs.c
@@ -92,7 +92,7 @@ struct mdinfo *sysfs_read(int fd, int devnum, unsigned long options)
        char *dbase;
        struct mdinfo *sra;
        struct mdinfo *dev;
-       DIR *dir;
+       DIR *dir = NULL;
        struct dirent *de;
 
        sra = malloc(sizeof(*sra));
@@ -253,9 +253,12 @@ struct mdinfo *sysfs_read(int fd, int devnum, unsigned long options)
                        dev->errors = strtoul(buf, NULL, 0);
                }
        }
+       closedir(dir);
        return sra;
 
  abort:
+       if (dir)
+               closedir(dir);
        sysfs_free(sra);
        return NULL;
 }
diff --git a/util.c b/util.c
index 8e4e60d..d026c30 100644 (file)
--- a/util.c
+++ b/util.c
@@ -982,6 +982,7 @@ int open_container(int fd)
                        return dfd;
                }
        }
+       closedir(dir);
        return -1;
 }