mirror of
https://git.proxmox.com/git/mirror_zfs.git
synced 2026-05-22 02:27:36 +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:
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user