Fix a couple of (not very likely) memory leaks, reported by enh@google.com

who attributed them:

  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>; Chris Ferris
  <cferris@google.com> then spotted the goto nospc one.
This commit is contained in:
kre 2023-12-07 22:33:49 +00:00
parent c62a59b56e
commit 058a868134
1 changed files with 4 additions and 2 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: sethostent.c,v 1.20 2014/03/17 13:24:23 christos Exp $ */
/* $NetBSD: sethostent.c,v 1.21 2023/12/07 22:33:49 kre Exp $ */
/*
* Copyright (c) 1985, 1993
@ -35,7 +35,7 @@
static char sccsid[] = "@(#)sethostent.c 8.1 (Berkeley) 6/4/93";
static char rcsid[] = "Id: sethostent.c,v 8.5 1996/09/28 06:51:07 vixie Exp ";
#else
__RCSID("$NetBSD: sethostent.c,v 1.20 2014/03/17 13:24:23 christos Exp $");
__RCSID("$NetBSD: sethostent.c,v 1.21 2023/12/07 22:33:49 kre Exp $");
#endif
#endif /* LIBC_SCCS and not lint */
@ -171,6 +171,7 @@ _hf_gethtbyname2(const char *name, int af, struct getnamaddr *info)
}
if ((ptr = buf = malloc(len = info->buflen)) == NULL) {
endhostent_r(&hf);
*info->he = NETDB_INTERNAL;
return NULL;
}
@ -251,6 +252,7 @@ _hf_gethtbyname2(const char *name, int af, struct getnamaddr *info)
free(buf);
return hp;
nospc:
endhostent_r(&hf);
*info->he = NETDB_INTERNAL;
free(buf);
errno = ENOSPC;