From 56e69c1e9ceeb20d40b8a443d7c0469267a23733 Mon Sep 17 00:00:00 2001 From: Allan Jude Date: Fri, 18 Sep 2020 13:23:29 -0400 Subject: [PATCH] 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 Signed-off-by: Allan Jude Closes #10882 --- lib/libzfs/libzfs_sendrecv.c | 1 + lib/libzfs/libzfs_util.c | 3 +++ 2 files changed, 4 insertions(+) diff --git a/lib/libzfs/libzfs_sendrecv.c b/lib/libzfs/libzfs_sendrecv.c index b17b105ca3..b46a4f122c 100644 --- a/lib/libzfs/libzfs_sendrecv.c +++ b/lib/libzfs/libzfs_sendrecv.c @@ -2640,6 +2640,7 @@ recv_read_nvlist(libzfs_handle_t *hdl, int fd, int len, nvlist_t **nvp, if (len > hdl->libzfs_max_nvlist) { zfs_error_aux(hdl, dgettext(TEXT_DOMAIN, "nvlist too large")); + free(buf); return (ENOMEM); } diff --git a/lib/libzfs/libzfs_util.c b/lib/libzfs/libzfs_util.c index 301c8ddbab..651bca2978 100644 --- a/lib/libzfs/libzfs_util.c +++ b/lib/libzfs/libzfs_util.c @@ -1060,6 +1060,9 @@ libzfs_init(void) if ((error = zfs_nicestrtonum(hdl, env, &hdl->libzfs_max_nvlist))) { errno = error; + (void) close(hdl->libzfs_fd); + (void) fclose(hdl->libzfs_mnttab); + free(hdl); return (NULL); } } else {