]> git.ipfire.org Git - thirdparty/mdadm.git/commitdiff
mdadm: Create.c fix coverity issues
authorNigel Croxon <ncroxon@redhat.com>
Fri, 5 Jul 2024 12:45:32 +0000 (08:45 -0400)
committerMariusz Tkaczyk <mariusz.tkaczyk@linux.intel.com>
Fri, 5 Jul 2024 13:28:25 +0000 (15:28 +0200)
* Event negative_returns: "fd" is passed to a parameter that cannot be negative. Which
is set to -1 to start.

* Event open_fn: Returning handle opened by "open_dev_excl".
* Event var_assign: Assigning: "container_fd" = handle returned from
"open_dev_excl(st->container_devnm)"
* Event leaked_handle: Handle variable "container_fd" going out of scope leaks the handle

Signed-off-by: Nigel Croxon <ncroxon@redhat.com>
Create.c

index 479c27158a48c9e74d98b923603ae6e25f9b605a..7fde1c1695226b28e6ca17a28f4b4e7804db19ca 100644 (file)
--- a/Create.c
+++ b/Create.c
@@ -297,7 +297,7 @@ static int add_disk_to_super(int mdfd, struct shape *s, struct context *c,
        if (st->ss->add_to_super(st, &info->disk, fd, dv->devname,
                                 dv->data_offset)) {
                ioctl(mdfd, STOP_ARRAY, NULL);
-               close(fd);
+               close_fd(&fd);
                return 1;
        }
        st->ss->getinfo_super(st, info, NULL);
@@ -1370,8 +1370,8 @@ int Create(struct supertype *st, struct mddev_ident *ident, int subdevs,
        map_remove(&map, fd2devnm(mdfd));
        map_unlock(&map);
 
-       if (mdfd >= 0)
-               close(mdfd);
+       close_fd(&mdfd);
+       close_fd(&container_fd);
 
        dev_policy_free(custom_pols);
        return 1;