mirror of
https://git.proxmox.com/git/mirror_zfs.git
synced 2026-05-23 02:44:41 +03:00
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 <behlendorf1@llnl.gov> Reviewed-by: Ryan Moeller <ryan@iXsystems.com> Signed-off-by: Richard Yao <richard.yao@alumni.stonybrook.edu> Closes #13921
This commit is contained in:
+8
-3
@@ -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",
|
||||
|
||||
+4
-1
@@ -7395,8 +7395,11 @@ unshare_unmount(int op, int argc, char **argv)
|
||||
((tree = uu_avl_create(pool, NULL, UU_DEFAULT)) == NULL))
|
||||
nomem();
|
||||
|
||||
if ((mnttab = fopen(MNTTAB, "re")) == NULL)
|
||||
if ((mnttab = fopen(MNTTAB, "re")) == NULL) {
|
||||
uu_avl_destroy(tree);
|
||||
uu_avl_pool_destroy(pool);
|
||||
return (ENOENT);
|
||||
}
|
||||
|
||||
while (getmntent(mnttab, &entry) == 0) {
|
||||
|
||||
|
||||
@@ -295,6 +295,8 @@ zhack_do_feature_enable(int argc, char **argv)
|
||||
feature.fi_flags |= ZFEATURE_FLAG_READONLY_COMPAT;
|
||||
break;
|
||||
case 'd':
|
||||
if (desc != NULL)
|
||||
free(desc);
|
||||
desc = strdup(optarg);
|
||||
break;
|
||||
default:
|
||||
|
||||
@@ -1196,6 +1196,7 @@ zpool_do_remove(int argc, char **argv)
|
||||
return (1);
|
||||
|
||||
if (stop && noop) {
|
||||
zpool_close(zhp);
|
||||
(void) fprintf(stderr, gettext("stop request ignored\n"));
|
||||
return (0);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user