From 494d1fdc82fa4c5a8ae0c976ea0076f9347ee800 Mon Sep 17 00:00:00 2001
From: root <root@localhost.localdomain>
Date: Wed, 13 Mar 2019 19:55:12 +0800
Subject: [PATCH 07/19] cov: fix failing filter initialization

When persistent_filter_create() fails, the existing passed filter
should be preserved, so it could be properly deleted on
error path - so new pfilter is assigned instead.
---
 lib/commands/toolcontext.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/lib/commands/toolcontext.c b/lib/commands/toolcontext.c
index ecd8fd7..df9ca75 100644
--- a/lib/commands/toolcontext.c
+++ b/lib/commands/toolcontext.c
@@ -1197,7 +1197,7 @@ bad:
 int init_filters(struct cmd_context *cmd, unsigned load_persistent_cache)
 {
 	const char *dev_cache;
-	struct dev_filter *filter = NULL, *filter_components[2] = {0};
+	struct dev_filter *pfilter, *filter = NULL, *filter_components[2] = {0};
 	int nr_filt;
 	struct stat st;
 	const struct dm_config_node *cn;
@@ -1250,12 +1250,12 @@ int init_filters(struct cmd_context *cmd, unsigned load_persistent_cache)
 	if (!(dev_cache = find_config_tree_str(cmd, devices_cache_CFG, NULL)))
 		goto_bad;
 
-	if (!(filter = persistent_filter_create(cmd->dev_types, filter, dev_cache))) {
+	if (!(pfilter = persistent_filter_create(cmd->dev_types, filter, dev_cache))) {
 		log_verbose("Failed to create persistent device filter.");
 		goto bad;
 	}
 
-	cmd->filter = filter;
+	cmd->filter = filter = pfilter;
 
 	if (lvmetad_used()) {
 		nr_filt = 0;
-- 
2.19.1

