]> www.infradead.org Git - users/hch/nvme-cli.git/commitdiff
nvme-cli:lightnvm:fix fd leak when do ioctl failed
authorWu Bo <wubo40@huawei.com>
Mon, 27 Apr 2020 13:12:25 +0000 (21:12 +0800)
committerKeith Busch <kbusch@kernel.org>
Mon, 27 Apr 2020 16:19:00 +0000 (10:19 -0600)
nvme-lightnvm.c

index b83310170256af6ee123e6438361ca97d5fe5b2c..d81fac6e13470e394ac567e1eaad08a1f5f3c665 100644 (file)
@@ -97,8 +97,10 @@ int lnvm_do_list_devices(void)
                return fd;
 
        ret = ioctl(fd, NVM_GET_DEVICES, &devs);
-       if (ret)
+       if (ret) {
+               lnvm_close(fd);
                return ret;
+       }
 
        printf("Number of devices: %u\n", devs.nr_devices);
        printf("%-12s\t%-12s\tVersion\n", "Device", "Block manager");
@@ -127,8 +129,10 @@ int lnvm_do_info(void)
 
        memset(&c, 0, sizeof(struct nvm_ioctl_info));
        ret = ioctl(fd, NVM_INFO, &c);
-       if (ret)
+       if (ret) {
+               lnvm_close(fd);
                return ret;
+       }
 
        printf("LightNVM (%u,%u,%u). %u target type(s) registered.\n",
                        c.version[0], c.version[1], c.version[2], c.tgtsize);