git: 2b0d4ae9ce61 - stable/13 - cap_net: plug memory leak

From: Mariusz Zaborski <oshogbo_at_FreeBSD.org>
Date: Sat, 12 Mar 2022 10:29:35 UTC
The branch stable/13 has been updated by oshogbo:

URL: https://cgit.FreeBSD.org/src/commit/?id=2b0d4ae9ce617effa72e469e8b0d113d2008bea8

commit 2b0d4ae9ce617effa72e469e8b0d113d2008bea8
Author:     Mariusz Zaborski <oshogbo@FreeBSD.org>
AuthorDate: 2021-12-14 10:57:36 +0000
Commit:     Mariusz Zaborski <oshogbo@FreeBSD.org>
CommitDate: 2022-03-12 10:28:52 +0000

    cap_net: plug memory leak
    
    MFC after:      5 days
    
    (cherry picked from commit 88910b8b7b14386e05bccda0317ace2bfd383ef5)
---
 lib/libcasper/services/cap_net/cap_net.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/lib/libcasper/services/cap_net/cap_net.c b/lib/libcasper/services/cap_net/cap_net.c
index a1a66a05b5a2..c6abaa69faf6 100644
--- a/lib/libcasper/services/cap_net/cap_net.c
+++ b/lib/libcasper/services/cap_net/cap_net.c
@@ -326,8 +326,10 @@ cap_getaddrinfo(cap_channel_t *chan, const char *hostname, const char *servname,
 			break;
 		nvlai = nvlist_get_nvlist(nvl, nvlname);
 		curai = addrinfo_unpack(nvlai);
-		if (curai == NULL)
+		if (curai == NULL) {
+			nvlist_destroy(nvl);
 			return (EAI_MEMORY);
+		}
 		if (prevai != NULL)
 			prevai->ai_next = curai;
 		else
@@ -896,8 +898,10 @@ net_getnameinfo(const nvlist_t *limits, const nvlist_t *nvlin, nvlist_t *nvlout)
 		error = EAI_FAIL;
 		goto out;
 	}
-	if (!net_allowed_bsaddr(funclimit, sabin, sabinsize))
-		return (ENOTCAPABLE);
+	if (!net_allowed_bsaddr(funclimit, sabin, sabinsize)) {
+		error = ENOTCAPABLE;
+		goto out;
+	}
 
 	memcpy(&sast, sabin, sabinsize);
 	salen = (socklen_t)sabinsize;