]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
libmount: check fstat() return code [coverity scan]
authorKarel Zak <kzak@redhat.com>
Wed, 17 May 2017 10:20:18 +0000 (12:20 +0200)
committerKarel Zak <kzak@redhat.com>
Wed, 17 May 2017 10:28:07 +0000 (12:28 +0200)
Signed-off-by: Karel Zak <kzak@redhat.com>
libfdisk/src/context.c

index 7dc16aa78a38b86df85256aaad784183eb8abbc4..02b035c928c379b66851fad10c70225b018d3b3d 100644 (file)
@@ -565,9 +565,10 @@ int fdisk_assign_device(struct fdisk_context *cxt,
 
        fd = open(fname, (readonly ? O_RDONLY : O_RDWR ) | O_CLOEXEC);
        if (fd < 0)
-               return -errno;
+               goto fail;
 
-       fstat(fd, &cxt->dev_st);
+       if (fstat(fd, &cxt->dev_st) != 0)
+               goto fail;
 
        cxt->readonly = readonly;
        cxt->dev_fd = fd;
@@ -597,6 +598,8 @@ int fdisk_assign_device(struct fdisk_context *cxt,
                              fname, readonly ? "READ-ONLY" : "READ-WRITE"));
        return 0;
 fail:
+       if (fd >= 0)
+               close(fd);
        DBG(CXT, ul_debugobj(cxt, "failed to assign device"));
        return -errno;
 }