From patchwork Fri Aug 18 08:32:45 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gu Jinxiang X-Patchwork-Id: 9907965 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 14F7560382 for ; Fri, 18 Aug 2017 08:33:11 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 02FC728C0F for ; Fri, 18 Aug 2017 08:33:11 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id EB12328C6B; Fri, 18 Aug 2017 08:33:10 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id F21AB28C0F for ; Fri, 18 Aug 2017 08:33:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751337AbdHRIdD (ORCPT ); Fri, 18 Aug 2017 04:33:03 -0400 Received: from mail.cn.fujitsu.com ([183.91.158.132]:65458 "EHLO heian.cn.fujitsu.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1750977AbdHRIdB (ORCPT ); Fri, 18 Aug 2017 04:33:01 -0400 X-IronPort-AV: E=Sophos;i="5.41,391,1498492800"; d="scan'208";a="24007810" Received: from localhost (HELO cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 18 Aug 2017 16:32:57 +0800 Received: from G08CNEXCHPEKD03.g08.fujitsu.local (unknown [10.167.33.85]) by cn.fujitsu.com (Postfix) with ESMTP id 1344447243A3 for ; Fri, 18 Aug 2017 16:32:54 +0800 (CST) Received: from localhost.localdomain (10.167.226.22) by G08CNEXCHPEKD03.g08.fujitsu.local (10.167.33.89) with Microsoft SMTP Server (TLS) id 14.3.319.2; Fri, 18 Aug 2017 16:32:54 +0800 From: Gu Jinxiang To: Subject: [PATCH 1/2] btrfs-progs: add necessary close(fd) in mkfs Date: Fri, 18 Aug 2017 01:32:45 -0700 Message-ID: <1503045166-18612-1-git-send-email-gujx@cn.fujitsu.com> X-Mailer: git-send-email 1.9.1 MIME-Version: 1.0 X-Originating-IP: [10.167.226.22] X-yoursite-MailScanner-ID: 1344447243A3.A463C X-yoursite-MailScanner: Found to be clean X-yoursite-MailScanner-From: gujx@cn.fujitsu.com Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Add some close(fd) when error occures in mkfs. And add close(fd) when end use it. Signed-off-by: Gu Jinxiang --- mkfs/main.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/mkfs/main.c b/mkfs/main.c index 2b109a5..ec82565 100644 --- a/mkfs/main.c +++ b/mkfs/main.c @@ -1694,6 +1694,7 @@ int main(int argc, char **argv) file, (unsigned long long)block_count, (unsigned long long)dev_block_count); + close(fd); exit(1); } } else { @@ -1711,6 +1712,7 @@ int main(int argc, char **argv) ret = zero_output_file(fd, block_count); if (ret) { error("unable to zero the output file"); + close(fd); exit(1); } /* our "device" is the new image file */ @@ -1721,6 +1723,7 @@ int main(int argc, char **argv) if (dev_block_count < BTRFS_MKFS_SYSTEM_GROUP_SIZE) { error("device is too small to make filesystem, must be at least %llu", (unsigned long long)BTRFS_MKFS_SYSTEM_GROUP_SIZE); + close(fd); exit(1); } @@ -1740,6 +1743,7 @@ int main(int argc, char **argv) ret = make_btrfs(fd, &mkfs_cfg); if (ret) { error("error during mkfs: %s", strerror(-ret)); + close(fd); exit(1); } @@ -1750,6 +1754,7 @@ int main(int argc, char **argv) close(fd); exit(1); } + close(fd); root = fs_info->fs_root; fs_info->alloc_start = alloc_start; @@ -1827,6 +1832,7 @@ int main(int argc, char **argv) sectorsize, sectorsize, sectorsize); if (ret) { error("unable to add %s to filesystem: %d", file, ret); + close(fd); goto out; } if (verbose >= 2) {