]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/commitdiff
xfsprogs: fix various fd leaks
authorEric Sandeen <sandeen@redhat.com>
Mon, 14 Apr 2014 01:34:01 +0000 (11:34 +1000)
committerDave Chinner <david@fromorbit.com>
Mon, 14 Apr 2014 01:34:01 +0000 (11:34 +1000)
Coverity spotted these; several paths where we don't
close fds when we return.

Signed-off-by: Eric Sandeen <sandeen@redhat.com>
Reviewed-by: Brian Foster <bfoster@redhat.com>
Signed-off-by: Dave Chinner <david@fromorbit.com>
fsr/xfs_fsr.c
io/readdir.c
libhandle/handle.c
mkfs/proto.c
quota/quot.c
rtcp/xfs_rtcp.c

index 6f00b415e0d1ca8714f3d8b6259e66ce1100c5b4..6b5d26090ae97aa57f4305d094efa4406a251401 100644 (file)
@@ -706,6 +706,7 @@ fsrfs(char *mntdir, xfs_ino_t startino, int targetrange)
        if (xfs_getgeom(fsfd, &fsgeom) < 0 ) {
                fsrprintf(_("Skipping %s: could not get XFS geometry\n"),
                          mntdir);
+               close(fsfd);
                return -1;
        }
 
@@ -1346,6 +1347,8 @@ packfile(char *fname, char *tname, int fd,
        if (lseek64(tfd, 0, SEEK_SET)) {
                fsrprintf(_("Couldn't rewind on temporary file\n"));
                close(tfd);
+               if (ffd != -1)
+                       close(ffd);
                free(fbuf);
                return -1;
        }
@@ -1359,6 +1362,8 @@ packfile(char *fname, char *tname, int fd,
                        fsrprintf(_("No improvement will be made (skipping): %s\n"), fname);
                free(fbuf);
                close(tfd);
+               if (ffd != -1)
+                       close(ffd);
                return 1; /* no change/no error */
        }
 
@@ -1432,6 +1437,8 @@ packfile(char *fname, char *tname, int fd,
                                }
                                free(fbuf);
                                close(tfd);
+                               if (ffd != -1)
+                                       close(ffd);
                                return -1;
                        }
                        if (nfrags) {
@@ -1446,7 +1453,8 @@ packfile(char *fname, char *tname, int fd,
                }
        }
        ftruncate64(tfd, statp->bs_size);
-       if (ffd > 0) close(ffd);
+       if (ffd != -1)
+               close(ffd);
        fsync(tfd);
 
        free(fbuf);
index 822818aecc644859635279f48e17176d4cd9b9fa..71332045db035986ac11c3237ed079ca82db2f5f 100644 (file)
@@ -171,6 +171,7 @@ readdir_f(
        gettimeofday(&t2, NULL);
 
        closedir(dir);
+       close(dfd);
 
        t2 = tsub(t2, t1);
        timestr(&t2, ts, sizeof(ts), 0);
index 9a232fa7861f3e2bf5d3a8fa973e6a3a121bcc98..9f81483b5a355693b9d73bb6658e0b7794c20d3e 100644 (file)
@@ -97,6 +97,7 @@ path_to_fshandle(
                /* new filesystem. add it to the cache */
                fdhp = malloc(sizeof(struct fdhash));
                if (fdhp == NULL) {
+                       close(fd);
                        errno = ENOMEM;
                        return -1;
                }
index 4d3680d43e0629f34557877175e41720367c5d81..b7e07618fba73562a40a7603440cac93eb0dc057 100644 (file)
@@ -59,18 +59,19 @@ setup_proto(
        if ((fd = open(fname, O_RDONLY)) < 0 || (size = filesize(fd)) < 0) {
                fprintf(stderr, _("%s: failed to open %s: %s\n"),
                        progname, fname, strerror(errno));
-               exit(1);
+               goto out_fail;
        }
+
        buf = malloc(size + 1);
        if (read(fd, buf, size) < size) {
                fprintf(stderr, _("%s: read failed on %s: %s\n"),
                        progname, fname, strerror(errno));
-               exit(1);
+               goto out_fail;
        }
        if (buf[size - 1] != '\n') {
                fprintf(stderr, _("%s: proto file %s premature EOF\n"),
                        progname, fname);
-               exit(1);
+               goto out_fail;
        }
        buf[size] = '\0';
        /*
@@ -79,7 +80,12 @@ setup_proto(
        (void)getstr(&buf);     /* boot image name */
        (void)getnum(&buf);     /* block count */
        (void)getnum(&buf);     /* inode count */
+       close(fd);
        return buf;
+
+out_fail:
+       close(fd);
+       exit(1);
 }
 
 static long
index a7782b44487d197df91085f7f9765c1cef947dc5..96d449ea71f3b9faf58acaa6ad28779aa89ded2d 100644 (file)
@@ -165,6 +165,7 @@ quot_bulkstat_mount(
        buf = (xfs_bstat_t *)calloc(NBSTAT, sizeof(xfs_bstat_t));
        if (!buf) {
                perror("calloc");
+               close(fsfd);
                return;
        }
 
index f0b59368ffb3d10e14676dc916af35d40e79cc12..b81b1e1b42654afb0641391b75fc7a3e9538ac6b 100644 (file)
@@ -224,6 +224,7 @@ rtcp( char *source, char *target, int fextsize)
                if ( !(fsxattr.fsx_xflags & XFS_XFLAG_REALTIME) ) {
                        fprintf(stderr, _("%s: %s is not a realtime file.\n"),
                                progname, tbuf);
+                       close( tofd );
                        return( -1 );
                }
 
@@ -234,6 +235,7 @@ rtcp( char *source, char *target, int fextsize)
                        fprintf(stderr, _("%s: %s file extent size is %d, "
                                        "instead of %d.\n"),
                                progname, tbuf, fsxattr.fsx_extsize, fextsize);
+                       close( tofd );
                        return( -1 );
                }
        }