From: Zhao Lei <zhaolei@cn.fujitsu.com>
To: <linux-btrfs@vger.kernel.org>
Cc: Zhao Lei <zhaolei@cn.fujitsu.com>
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 [thread overview]
Message-ID: <c062cb5cd334c0dd785a3c95e474dc8e7be5e44e.1445855131.git.zhaolei@cn.fujitsu.com> (raw)
In-Reply-To: <cover.1445855131.git.zhaolei@cn.fujitsu.com>
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 <dsterba@suse.cz>
Signed-off-by: Zhao Lei <zhaolei@cn.fujitsu.com>
---
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 <stdlib.h>
#include <string.h>
+#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);
}
--
1.8.5.1
next prev parent reply other threads:[~2015-10-26 10:30 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-10-26 10:28 [PATCH v2 0/5] btrfs-progs: Add all missing close_ctree and btrfs_close_all_devices Zhao Lei
2015-10-26 10:28 ` Zhao Lei [this message]
2015-10-26 10:28 ` [PATCH v2 2/5] btrfs-progs: Remove all btrfs_close_all_devices in sub-command Zhao Lei
2015-10-26 10:28 ` [PATCH v2 3/5] btrfs-progs: Add all missing btrfs_close_all_devices to standalone tools Zhao Lei
2015-10-26 10:28 ` [PATCH v2 4/5] btrfs-progs: Add missing close_ctree to btrfs-select-super.c Zhao Lei
2015-10-26 10:28 ` [PATCH v2 5/5] btrfs-progs: use system's default path for math.h Zhao Lei
2015-10-26 14:57 ` [PATCH v2 0/5] btrfs-progs: Add all missing close_ctree and btrfs_close_all_devices David Sterba
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=c062cb5cd334c0dd785a3c95e474dc8e7be5e44e.1445855131.git.zhaolei@cn.fujitsu.com \
--to=zhaolei@cn.fujitsu.com \
--cc=linux-btrfs@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.