kpartx(coverity): fix resource leak warning
authorMartin Wilck <mwilck@suse.com>
Tue, 8 Jan 2019 22:53:58 +0000 (23:53 +0100)
committerChristophe Varoqui <christophe.varoqui@opensvc.com>
Sat, 19 Jan 2019 10:41:32 +0000 (11:41 +0100)
This was an easy-to-fix false positive.

Signed-off-by: Martin Wilck <mwilck@suse.com>
kpartx/dasd.c

index 94ae81b..fb358ad 100644 (file)
@@ -137,7 +137,7 @@ read_dasd_pt(int fd, struct slice all, struct slice *sp, int ns)
                        /* Not a DASD */
                        return -1;
        } else {
-               fd_dasd = fd;
+               fd_dasd = dup(fd);
        }
 
        if (ioctl(fd_dasd, BIODASDINFO, (unsigned long)&info) != 0) {
@@ -288,7 +288,6 @@ read_dasd_pt(int fd, struct slice all, struct slice *sp, int ns)
 out:
        if (data != NULL)
                free(data);
-       if (fd_dasd != -1 && fd_dasd != fd)
-               close(fd_dasd);
+       close(fd_dasd);
        return retval;
 }