From 12ba2d58c302b3c291333c19ece90c33f1584802 Mon Sep 17 00:00:00 2001 From: ngie Date: Sun, 28 May 2017 07:40:42 +0000 Subject: [PATCH] hostent_test_getaddrinfo_eq(..): call freeaddrinfo on `ai` when done This plugs a leak of memory allocated via getaddrinfo. MFC after: 1 week Reported by: Coverity CID: 1346866 Sponsored by: Dell EMC Isilon --- lib/libc/tests/nss/gethostby_test.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/lib/libc/tests/nss/gethostby_test.c b/lib/libc/tests/nss/gethostby_test.c index 214d29a05a2e..39dbb9d9d55a 100644 --- a/lib/libc/tests/nss/gethostby_test.c +++ b/lib/libc/tests/nss/gethostby_test.c @@ -776,24 +776,26 @@ hostent_test_getaddrinfo_eq(struct hostent *he, void *mdata __unused) rv = getaddrinfo(he->h_name, NULL, &hints, &ai); if (rv == 0) { printf("not ok - shouldn't have been resolved\n"); - return (-1); - } + rv = -1; + } else + rv = 0; } else { rv = getaddrinfo(he->h_name, NULL, &hints, &ai); if (rv != 0) { printf("not ok - should have been resolved\n"); - return (-1); + rv = -1; + goto done; } - rv = is_hostent_equal(he, ai); if (rv != 0) { printf("not ok - addrinfo and hostent are not equal\n"); - return (-1); + rv = -1; } - } - - return (0); +done: + if (ai != NULL) + freeaddrinfo(ai); + return (rv); } static int