Merge "Closing the stream when the function returns" into main am: 14b322b251 am: dd9d3cd9a0

Original change: https://android-review.googlesource.com/c/platform/bionic/+/2856549

Change-Id: Ib12e904f6e407c7bc7b303391fd4c6e1b538a5f7
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
diff --git a/libc/dns/net/sethostent.c b/libc/dns/net/sethostent.c
index 483105a..5c4bdb5 100644
--- a/libc/dns/net/sethostent.c
+++ b/libc/dns/net/sethostent.c
@@ -157,6 +157,7 @@
 
 	if ((ptr = buf = malloc(len = info->buflen)) == NULL) {
 		*info->he = NETDB_INTERNAL;
+		endhostent_r(&hf);
 		return NULL;
 	}
 
@@ -241,6 +242,7 @@
 	return hp;
 nospc:
 	*info->he = NETDB_INTERNAL;
+	endhostent_r(&hf);
 	free(buf);
 	errno = ENOSPC;
 	return NULL;