[PATCH v2 2/9] do_discover: free cfg.device when resetting it
mwilck at suse.com
mwilck at suse.com
Tue Mar 30 16:57:04 BST 2021
From: Martin Wilck <mwilck at suse.com>
cfg.device might have been allocated by a previous call to
find_ctrl_with_connectargs(), therefore free it. We must make sure
that cfg.device is always on the heap, thus change fabrics_discover()
accordingly.
Signed-off-by: Martin Wilck <mwilck at suse.com>
---
fabrics.c | 15 ++++++++++++---
1 file changed, 12 insertions(+), 3 deletions(-)
diff --git a/fabrics.c b/fabrics.c
index bdd0679..49331cd 100644
--- a/fabrics.c
+++ b/fabrics.c
@@ -1376,7 +1376,11 @@ static int do_discover(char *argstr, bool connect, enum nvme_print_flags flags)
if (!cargs)
return -ENOMEM;
- if (!cfg.device || !ctrl_matches_connectargs(cfg.device, cargs))
+ if (cfg.device && !ctrl_matches_connectargs(cfg.device, cargs)) {
+ free(cfg.device);
+ cfg.device = NULL;
+ }
+ if (!cfg.device)
cfg.device = find_ctrl_with_connectargs(cargs);
free_connect_args(cargs);
@@ -1560,8 +1564,13 @@ int fabrics_discover(const char *desc, int argc, char **argv, bool connect)
ret = flags = validate_output_format(cfg.output_format);
if (ret < 0)
goto out;
- if (cfg.device && !strcmp(cfg.device, "none"))
- cfg.device = NULL;
+ if (cfg.device && strcmp(cfg.device, "none")) {
+ cfg.device = strdup(cfg.device);
+ if (!cfg.device) {
+ ret = -ENOMEM;
+ goto out;
+ }
+ }
cfg.nqn = NVME_DISC_SUBSYS_NAME;
--
2.30.1
More information about the Linux-nvme
mailing list