Module Name:    src
Committed By:   kre
Date:           Thu Dec  7 22:33:49 UTC 2023

Modified Files:
        src/lib/libc/net: sethostent.c

Log Message:
Fix a couple of (not very likely) memory leaks, reported by e...@google.com
who attributed them:

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


To generate a diff of this commit:
cvs rdiff -u -r1.20 -r1.21 src/lib/libc/net/sethostent.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libc/net/sethostent.c
diff -u src/lib/libc/net/sethostent.c:1.20 src/lib/libc/net/sethostent.c:1.21
--- src/lib/libc/net/sethostent.c:1.20	Mon Mar 17 13:24:23 2014
+++ src/lib/libc/net/sethostent.c	Thu Dec  7 22:33:49 2023
@@ -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 a
 	}
 
 	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 a
 	free(buf);
 	return hp;
 nospc:
+	endhostent_r(&hf);
 	*info->he = NETDB_INTERNAL;
 	free(buf);
 	errno = ENOSPC;

Reply via email to