libzfs: Don't leak buf if nvlist is too large

Resolves FreeBSD Coverity defect:
CID 1432398:  Resource leaks  (RESOURCE_LEAK)

libzfs: don't leak hdl if there is an error reading env var

Resolves FreeBSD Coverity defect:
CID 1432395:  Resource leaks  (RESOURCE_LEAK)

Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Signed-off-by: Allan Jude <allanjude@freebsd.org>
Closes #10882
This commit is contained in:
Allan Jude 2020-09-18 13:23:29 -04:00 committed by Brian Behlendorf
parent dacb4f6a61
commit 56e69c1e9c
2 changed files with 4 additions and 0 deletions

View File

@ -2640,6 +2640,7 @@ recv_read_nvlist(libzfs_handle_t *hdl, int fd, int len, nvlist_t **nvp,
if (len > hdl->libzfs_max_nvlist) { if (len > hdl->libzfs_max_nvlist) {
zfs_error_aux(hdl, dgettext(TEXT_DOMAIN, "nvlist too large")); zfs_error_aux(hdl, dgettext(TEXT_DOMAIN, "nvlist too large"));
free(buf);
return (ENOMEM); return (ENOMEM);
} }

View File

@ -1060,6 +1060,9 @@ libzfs_init(void)
if ((error = zfs_nicestrtonum(hdl, env, if ((error = zfs_nicestrtonum(hdl, env,
&hdl->libzfs_max_nvlist))) { &hdl->libzfs_max_nvlist))) {
errno = error; errno = error;
(void) close(hdl->libzfs_fd);
(void) fclose(hdl->libzfs_mnttab);
free(hdl);
return (NULL); return (NULL);
} }
} else { } else {