aboutsummaryrefslogtreecommitdiffstats
path: root/cmd/zdb
diff options
context:
space:
mode:
authorRichard Yao <[email protected]>2022-09-23 19:55:26 -0400
committerGitHub <[email protected]>2022-09-23 16:55:26 -0700
commitebe1d0361671c80025d5be2c31131ed223115873 (patch)
tree04f6b7e5a3af21a543afe7d4afa4465908cd4a29 /cmd/zdb
parent2a493a4c7127258b14c39e8c71a9d6f01167c5cd (diff)
Fix userland resource leaks
Coverity caught these. With the exception of the file descriptor leak in tests/zfs-tests/cmd/draid.c, they are all memory leaks. Also, there is a piece of dead code in zfs_get_enclosure_sysfs_path(). We delete it as cleanup. Reviewed-by: Brian Behlendorf <[email protected]> Reviewed-by: Ryan Moeller <[email protected]> Signed-off-by: Richard Yao <[email protected]> Closes #13921
Diffstat (limited to 'cmd/zdb')
-rw-r--r--cmd/zdb/zdb.c11
1 files changed, 8 insertions, 3 deletions
diff --git a/cmd/zdb/zdb.c b/cmd/zdb/zdb.c
index a17793c2d..aa8b67a87 100644
--- a/cmd/zdb/zdb.c
+++ b/cmd/zdb/zdb.c
@@ -1137,6 +1137,8 @@ dump_uint64(objset_t *os, uint64_t object, void *data, size_t size)
}
if (size == 0) {
+ if (data == NULL)
+ kmem_free(arr, oursize);
(void) printf("\t\t[]\n");
return;
}
@@ -7062,8 +7064,11 @@ import_checkpointed_state(char *target, nvlist_t *cfg, char **new_path)
freecfg = B_TRUE;
}
- if (asprintf(&bogus_name, "%s%s", poolname, BOGUS_SUFFIX) == -1)
+ if (asprintf(&bogus_name, "%s%s", poolname, BOGUS_SUFFIX) == -1) {
+ if (target != poolname)
+ free(poolname);
return (NULL);
+ }
fnvlist_add_string(cfg, ZPOOL_CONFIG_POOL_NAME, bogus_name);
error = spa_import(bogus_name, cfg, NULL,
@@ -7078,6 +7083,7 @@ import_checkpointed_state(char *target, nvlist_t *cfg, char **new_path)
if (new_path != NULL && path_start != NULL) {
if (asprintf(new_path, "%s%s", bogus_name, path_start) == -1) {
+ free(bogus_name);
if (path_start != NULL)
free(poolname);
return (NULL);
@@ -8198,8 +8204,7 @@ zdb_read_block(char *thing, spa_t *spa)
vd = zdb_vdev_lookup(spa->spa_root_vdev, vdev);
if (vd == NULL) {
(void) printf("***Invalid vdev: %s\n", vdev);
- free(dup);
- return;
+ goto done;
} else {
if (vd->vdev_path)
(void) fprintf(stderr, "Found vdev: %s\n",