]> granicus.if.org Git - file/commitdiff
- don't close if not needed
authorChristos Zoulas <christos@zoulas.com>
Wed, 16 Nov 2011 19:24:22 +0000 (19:24 +0000)
committerChristos Zoulas <christos@zoulas.com>
Wed, 16 Nov 2011 19:24:22 +0000 (19:24 +0000)
- closedir on error path

src/apprentice.c

index c773a942620ce206888043547dda9fb6dcc2f309..a22a3dba83d2c1cc6db1a8f12290ee4e2591c1e7 100644 (file)
@@ -32,7 +32,7 @@
 #include "file.h"
 
 #ifndef        lint
-FILE_RCSID("@(#)$File: apprentice.c,v 1.170 2011/06/10 09:23:28 christos Exp $")
+FILE_RCSID("@(#)$File: apprentice.c,v 1.171 2011/09/16 21:04:59 christos Exp $")
 #endif /* lint */
 
 #include "magic.h"
@@ -790,6 +790,7 @@ apprentice_load(struct magic_set *ms, struct magic **magicp, uint32_t *nmagicp,
                                file_oomem(ms,
                                    strlen(fn) + strlen(d->d_name) + 2);
                                errs++;
+                               closedir(dir);
                                goto out;
                        }
                        if (stat(mfn, &st) == -1 || !S_ISREG(st.st_mode)) {
@@ -804,6 +805,7 @@ apprentice_load(struct magic_set *ms, struct magic **magicp, uint32_t *nmagicp,
                                    realloc(filearr, mlen))) == NULL) {
                                        file_oomem(ms, mlen);
                                        free(mfn);
+                                       closedir(dir);
                                        errs++;
                                        goto out;
                                }
@@ -2300,7 +2302,7 @@ private int
 apprentice_compile(struct magic_set *ms, struct magic **magicp,
     uint32_t *nmagicp, const char *fn)
 {
-       int fd;
+       int fd = -1;
        char *dbname;
        int rv = -1;
 
@@ -2331,7 +2333,8 @@ apprentice_compile(struct magic_set *ms, struct magic **magicp,
                goto out;
        }
 
-       (void)close(fd);
+       if (fd != -1)
+               (void)close(fd);
        rv = 0;
 out:
        free(dbname);