]> www.infradead.org Git - mtd-utils.git/commitdiff
mkfs.ubifs: Fix missed closing out_fd
authorZhihao Cheng <chengzhihao1@huawei.com>
Thu, 22 Feb 2024 12:27:58 +0000 (20:27 +0800)
committerDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>
Wed, 25 Sep 2024 07:08:41 +0000 (09:08 +0200)
Closing 'out_fd' is missed in handling paths in open_target(), fix it
by adding closing operations before returning.

Fixes: a48340c335dab ("mkfs.ubifs: use libubi to format UBI volume")
Signed-off-by: Zhihao Cheng <chengzhihao1@huawei.com>
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
ubifs-utils/mkfs.ubifs/mkfs.ubifs.c

index f5e2eb28ebd275c28280a79b249d4b1ac9fea4bc..453a5c76cdfbaf7a57a85691691f8be0ea811ccd 100644 (file)
@@ -2848,12 +2848,16 @@ static int open_target(void)
                if (out_fd == -1)
                        return sys_err_msg("cannot open the UBI volume '%s'",
                                           output);
-               if (ubi_set_property(out_fd, UBI_VOL_PROP_DIRECT_WRITE, 1))
+               if (ubi_set_property(out_fd, UBI_VOL_PROP_DIRECT_WRITE, 1)) {
+                       close(out_fd);
                        return sys_err_msg("ubi_set_property(set direct_write) failed");
+               }
 
                if (!yes && check_volume_empty()) {
-                       if (!prompt("UBI volume is not empty.  Format anyways?", false))
+                       if (!prompt("UBI volume is not empty.  Format anyways?", false)) {
+                               close(out_fd);
                                return err_msg("UBI volume is not empty");
+                       }
                }
        } else {
                out_fd = open(output, O_CREAT | O_RDWR | O_TRUNC,