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:
Richard Yao
2022-09-23 19:55:26 -04:00
committed by GitHub
parent 2a493a4c71
commit ebe1d03616
8 changed files with 22 additions and 8 deletions
+1
View File
@@ -2007,6 +2007,7 @@ zfs_prop_inherit(zfs_handle_t *zhp, const char *propname, boolean_t received)
goto error;
if ((ret = zfs_ioctl(zhp->zfs_hdl, ZFS_IOC_INHERIT_PROP, &zc)) != 0) {
changelist_free(cl);
return (zfs_standard_error(hdl, errno, errbuf));
} else {
+4 -3
View File
@@ -344,6 +344,8 @@ zfs_get_enclosure_sysfs_path(const char *dev_name)
if (strstr(ep->d_name, "enclosure_device") == NULL)
continue;
if (tmp2 != NULL)
free(tmp2);
if (asprintf(&tmp2, "%s/%s", tmp1, ep->d_name) == -1) {
tmp2 = NULL;
break;
@@ -372,14 +374,13 @@ zfs_get_enclosure_sysfs_path(const char *dev_name)
if (tmp3 == NULL)
break;
if (path != NULL)
free(path);
if (asprintf(&path, "/sys/class/%s", tmp3) == -1) {
/* If asprintf() fails, 'path' is undefined */
path = NULL;
break;
}
if (path == NULL)
break;
}
end: