summaryrefslogtreecommitdiffstats
path: root/cmd/zpool/zpool_iter.c
diff options
context:
space:
mode:
authorнаб <[email protected]>2021-05-03 11:36:02 +0200
committerBrian Behlendorf <[email protected]>2021-05-10 12:21:12 -0700
commit214ae461f1846fd14e3b92ff9b748d0bcf30946c (patch)
tree1a8d55c74381465debab3a5338e350781fa44880 /cmd/zpool/zpool_iter.c
parent12ed5275d138123b5c67e90494bde213b78337cc (diff)
zpool: vdev_run_cmd(): don't free undefined pointers
Reviewed-by: Brian Behlendorf <[email protected]> Signed-off-by: Ahelenia Ziemiańska <[email protected]> Closes #11993
Diffstat (limited to 'cmd/zpool/zpool_iter.c')
-rw-r--r--cmd/zpool/zpool_iter.c15
1 files changed, 10 insertions, 5 deletions
diff --git a/cmd/zpool/zpool_iter.c b/cmd/zpool/zpool_iter.c
index d70d26669..3d7a0cfc3 100644
--- a/cmd/zpool/zpool_iter.c
+++ b/cmd/zpool/zpool_iter.c
@@ -494,19 +494,25 @@ vdev_run_cmd(vdev_cmd_data_t *data, char *cmd)
/* Setup our custom environment variables */
rc = asprintf(&env[1], "VDEV_PATH=%s",
data->path ? data->path : "");
- if (rc == -1)
+ if (rc == -1) {
+ env[1] = NULL;
goto out;
+ }
rc = asprintf(&env[2], "VDEV_UPATH=%s",
data->upath ? data->upath : "");
- if (rc == -1)
+ if (rc == -1) {
+ env[2] = NULL;
goto out;
+ }
rc = asprintf(&env[3], "VDEV_ENC_SYSFS_PATH=%s",
data->vdev_enc_sysfs_path ?
data->vdev_enc_sysfs_path : "");
- if (rc == -1)
+ if (rc == -1) {
+ env[3] = NULL;
goto out;
+ }
/* Run the command */
rc = libzfs_run_process_get_stdout_nopath(cmd, argv, env, &lines,
@@ -525,8 +531,7 @@ out:
/* Start with i = 1 since env[0] was statically allocated */
for (i = 1; i < ARRAY_SIZE(env); i++)
- if (env[i] != NULL)
- free(env[i]);
+ free(env[i]);
}
/*