From patchwork Mon Oct 26 10:28:18 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhaolei X-Patchwork-Id: 7486821 Return-Path: X-Original-To: patchwork-linux-btrfs@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 6E77ABEEA4 for ; Mon, 26 Oct 2015 10:30:17 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 61FC0207E1 for ; Mon, 26 Oct 2015 10:30:16 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 86B7E207DD for ; Mon, 26 Oct 2015 10:30:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753898AbbJZKaI (ORCPT ); Mon, 26 Oct 2015 06:30:08 -0400 Received: from cn.fujitsu.com ([59.151.112.132]:1221 "EHLO heian.cn.fujitsu.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1753798AbbJZKaE (ORCPT ); Mon, 26 Oct 2015 06:30:04 -0400 X-IronPort-AV: E=Sophos;i="5.15,520,1432569600"; d="scan'208";a="102287529" Received: from bogon (HELO edo.cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 26 Oct 2015 18:32:17 +0800 Received: from G08CNEXCHPEKD01.g08.fujitsu.local (localhost.localdomain [127.0.0.1]) by edo.cn.fujitsu.com (8.14.3/8.13.1) with ESMTP id t9QATT4l004075 for ; Mon, 26 Oct 2015 18:29:29 +0800 Received: from localhost.localdomain (10.167.226.114) by G08CNEXCHPEKD01.g08.fujitsu.local (10.167.33.89) with Microsoft SMTP Server id 14.3.181.6; Mon, 26 Oct 2015 18:30:01 +0800 From: Zhao Lei To: CC: Zhao Lei Subject: [PATCH v2 1/5] btrfs-progs: btrfs: Add missing btrfs_close_all_devices for btrfs command Date: Mon, 26 Oct 2015 18:28:18 +0800 Message-ID: X-Mailer: git-send-email 1.8.5.1 In-Reply-To: References: MIME-Version: 1.0 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Adding a btrfs_close_all_devices() after command callback in btrfs.c can force-close all opened device before program exit, to avoid memory leak in all btrfs sub-command. Suggested-by: David Sterba Signed-off-by: Zhao Lei --- btrfs.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/btrfs.c b/btrfs.c index 63df377..9416a29 100644 --- a/btrfs.c +++ b/btrfs.c @@ -18,6 +18,7 @@ #include #include +#include "volumes.h" #include "crc32c.h" #include "commands.h" #include "utils.h" @@ -214,6 +215,7 @@ int main(int argc, char **argv) { const struct cmd_struct *cmd; const char *bname; + int ret; if ((bname = strrchr(argv[0], '/')) != NULL) bname++; @@ -242,5 +244,10 @@ int main(int argc, char **argv) crc32c_optimization_init(); fixup_argv0(argv, cmd->token); - exit(cmd->fn(argc, argv)); + + ret = cmd->fn(argc, argv); + + btrfs_close_all_devices(); + + exit(ret); }