tech-userlevel archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

resource leaks in sethostent.c



the malloc one was reported to Android (as
https://android-review.googlesource.com/c/platform/bionic/+/2856549)
by wuhaitao3 <wuhaitao3%xiaomi.corp-partner.google.com@localhost>; Chris Ferris
<cferris%google.com@localhost> then spotted the goto nospc one.

the other function in the file looks fine.
diff --git a/lib/libc/net/sethostent.c b/lib/libc/net/sethostent.c
index b5f7ac8f2058..1029b3308c93 100644
--- a/lib/libc/net/sethostent.c
+++ b/lib/libc/net/sethostent.c
@@ -172,6 +172,7 @@ _hf_gethtbyname2(const char *name, int af, struct getnamaddr *info)
 
 	if ((ptr = buf = malloc(len = info->buflen)) == NULL) {
 		*info->he = NETDB_INTERNAL;
+		endhostent_r(&hf);
 		return NULL;
 	}
 
@@ -252,6 +253,7 @@ _hf_gethtbyname2(const char *name, int af, struct getnamaddr *info)
 	return hp;
 nospc:
 	*info->he = NETDB_INTERNAL;
+	endhostent_r(&hf);
 	free(buf);
 	errno = ENOSPC;
 	return NULL;


Home | Main Index | Thread Index | Old Index