Received: by 2002:ab2:6309:0:b0:1fb:d597:ff75 with SMTP id s9csp806712lqt; Thu, 6 Jun 2024 21:29:18 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVREqxV/k8EdLGrp6PvjGC5NlPQzFdO8usQtvmtuj0d8+OGRDl4NrI9VBK2QY0TlujEfLpFOwRQq+gaHULI60IZlJtKM6df6m2yVrVROg== X-Google-Smtp-Source: AGHT+IF9vWtwiKxYu9XdZ/qHRFmwX6uz6lKfUH9SxED97YK6Z06hQdq3K/sIznRXy6wcL55Kze7f X-Received: by 2002:a17:906:ce41:b0:a68:ff92:46f1 with SMTP id a640c23a62f3a-a6cb934156amr125900666b.2.1717734558126; Thu, 06 Jun 2024 21:29:18 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1717734558; cv=pass; d=google.com; s=arc-20160816; b=y40kIceWyHv66SmqNfSHX5wKgdi63P/GZwuKQerw1zvZSJTtthZUXsx0GHkQnXb6iN gJFaEXUtPy/gd6KD39iU4LA6camh74EhhqvuFkPag9rKbeOWnkrQWEu/noEhzT1DXXvj wZCehLJcoCyYwnDB3EI239Eec7iP21912jgo3+B8HAO29Jlt+BP+Oq93N0wbmvwtu18P N+QNLR+A2hpjeXxVKyNqY+IkhAXfvFT8tQLrJdkWG3V8bMZUGfkfrMCknAgoyJXiOFZB pVetSPFOvwYHFvv4yS4leNrdVWarfDQRn5H4arq7a/rMaYat9OG+dFYFMxGMgys6tJUR 9/Tw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from; bh=es2qUm0bk8u7l6e6m5KyYMT3hYxgBuBJHmhS/o3FWdY=; fh=yXYChwFvQA/NaaLzCC0IJdkW11OhjXgO4DHXzVmnGFw=; b=WYT6bxAz4nOs/xWfQ+8+9G53pUJHlo0D+pbtRPWcStogmjlQ/9edBR77NO7FbSc8CF TCH3r4AfnIIaDeZQ52Hln6aXe6I3UMTfuMy/R3WwTjNAfmYB2/OhUM639ojXOt+RbcLp vmih+vgVnQiCPt/MrK4MHCOy+7+l1wxYs8nzktNc3Ujl21QECy9sZdh1z8j7/GlhXn8P B5LVNojBduokYKsu68F8XdU52xOKTWxm/drwyobEEyv0dyx8rM5f7347DmpE6eSkImue 0cU2TbGvnA+qbx9Zzk+ygIB+8hpzpqePjZjZ/VQQtZXdEjv+h6NaU8MEbqCjYbBbTdG7 v/YA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=huawei.com dmarc=pass fromdomain=huawei.com); spf=pass (google.com: domain of linux-kernel+bounces-205292-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-205292-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id a640c23a62f3a-a6c849f0e48si125402766b.228.2024.06.06.21.29.18 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 06 Jun 2024 21:29:18 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-205292-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=huawei.com dmarc=pass fromdomain=huawei.com); spf=pass (google.com: domain of linux-kernel+bounces-205292-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-205292-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id D21281F2552E for ; Fri, 7 Jun 2024 04:29:17 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 1F53D13FD84; Fri, 7 Jun 2024 04:26:55 +0000 (UTC) Received: from szxga08-in.huawei.com (szxga08-in.huawei.com [45.249.212.255]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7FED013E04F for ; Fri, 7 Jun 2024 04:26:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.255 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717734414; cv=none; b=UUzeuBjHdLCApjRj8qXP3pgA38Pw71lCST+HTGO0DxXMV61KixT7StCRPCrf2OmoNxVXB1RRLti3Wx3bf1MIwMVThFVXwfqY3NyEm2H5oYpKPz7qNYANlIIwXhvt22FYmzcjIiKXq+Fv215HgZ8r/1eTay8TgHF3jDT+eA/C0TM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717734414; c=relaxed/simple; bh=1irDstytzNPyT8cxCLPG0N57rj/rgKgKzkw2iReGzUk=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=IOy7av5qKwb77gx3epSowyh6vbdxT6i2aKIhvkGL8Qmq5TFGYXjv0+2Xak0HrT+wjcT9/5WpUF+F/vi8nnRxfo6wm+7zDFL83skkJzqnXtAKCV2UH6qWOzJze5aG3aSoeOMud+JV+zwJHD6zs/6dHMIIgA5o9ZOUydhNgKyfB9A= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; arc=none smtp.client-ip=45.249.212.255 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Received: from mail.maildlp.com (unknown [172.19.88.194]) by szxga08-in.huawei.com (SkyGuard) with ESMTP id 4VwSjR4D24z1SB5B; Fri, 7 Jun 2024 12:22:51 +0800 (CST) Received: from kwepemm600013.china.huawei.com (unknown [7.193.23.68]) by mail.maildlp.com (Postfix) with ESMTPS id 543FA14038F; Fri, 7 Jun 2024 12:26:50 +0800 (CST) Received: from huawei.com (10.175.104.67) by kwepemm600013.china.huawei.com (7.193.23.68) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.39; Fri, 7 Jun 2024 12:26:34 +0800 From: Zhihao Cheng To: , , , , , CC: , Subject: [RFC PATCH mtd-utils 011/110] mkfs.ubifs: Fix missed closing out_fd Date: Fri, 7 Jun 2024 12:24:36 +0800 Message-ID: <20240607042615.2069840-12-chengzhihao1@huawei.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240607042615.2069840-1-chengzhihao1@huawei.com> References: <20240607042615.2069840-1-chengzhihao1@huawei.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) To kwepemm600013.china.huawei.com (7.193.23.68) 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 --- ubifs-utils/mkfs.ubifs/mkfs.ubifs.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/ubifs-utils/mkfs.ubifs/mkfs.ubifs.c b/ubifs-utils/mkfs.ubifs/mkfs.ubifs.c index 6a4a4588..949187ea 100644 --- a/ubifs-utils/mkfs.ubifs/mkfs.ubifs.c +++ b/ubifs-utils/mkfs.ubifs/mkfs.ubifs.c @@ -2860,12 +2860,16 @@ static int open_target(void) if (out_fd == -1) return sys_errmsg("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_errmsg("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 errmsg("UBI volume is not empty"); + } } } else { out_fd = open(output, O_CREAT | O_RDWR | O_TRUNC, -- 2.13.6