summaryrefslogtreecommitdiffstats
path: root/lib/libc
diff options
context:
space:
mode:
authorkib <kib@FreeBSD.org>2017-09-21 10:16:25 +0000
committerkib <kib@FreeBSD.org>2017-09-21 10:16:25 +0000
commit15ee484f9917ffcca40218921d373189e9fe4aba (patch)
tree7980bda2fcee8c175d8ee891c30c77e55d4475ca /lib/libc
parent6d630a40a4438ee9c40168983260089b6498c44a (diff)
downloadFreeBSD-src-15ee484f9917ffcca40218921d373189e9fe4aba.zip
FreeBSD-src-15ee484f9917ffcca40218921d373189e9fe4aba.tar.gz
MFC r323597:
Handle freeaddrinfo(NULL).
Diffstat (limited to 'lib/libc')
-rw-r--r--lib/libc/net/getaddrinfo.313
-rw-r--r--lib/libc/net/getaddrinfo.c9
2 files changed, 16 insertions, 6 deletions
diff --git a/lib/libc/net/getaddrinfo.3 b/lib/libc/net/getaddrinfo.3
index 7380428..fdfaddb 100644
--- a/lib/libc/net/getaddrinfo.3
+++ b/lib/libc/net/getaddrinfo.3
@@ -18,7 +18,7 @@
.\"
.\" $FreeBSD$
.\"
-.Dd December 21, 2015
+.Dd September 13, 2017
.Dt GETADDRINFO 3
.Os
.Sh NAME
@@ -351,6 +351,17 @@ pointer should be a
.Li addrinfo
structure created by a call to
.Fn getaddrinfo .
+.Sh IMPLEMENTATION NOTES
+The behavior of
+.Li freeadrinfo(NULL)
+is left unspecified by both
+.St -susv4
+and
+.Dv "RFC 3493" .
+The current implementation ignores a
+.Dv NULL
+argument for compatibility with programs that rely on the implementation
+details of other operating systems.
.Sh RETURN VALUES
.Fn getaddrinfo
returns zero on success or one of the error codes listed in
diff --git a/lib/libc/net/getaddrinfo.c b/lib/libc/net/getaddrinfo.c
index 5988ebc..d705028 100644
--- a/lib/libc/net/getaddrinfo.c
+++ b/lib/libc/net/getaddrinfo.c
@@ -35,7 +35,7 @@
* in the source code. This is because RFC2553 is silent about which error
* code must be returned for which situation.
* - freeaddrinfo(NULL). RFC2553 is silent about it. XNET 5.2 says it is
- * invalid. current code - SEGV on freeaddrinfo(NULL)
+ * invalid. Current code accepts NULL to be compatible with other OSes.
*
* Note:
* - The code filters out AFs that are not supported by the kernel,
@@ -359,14 +359,13 @@ freeaddrinfo(struct addrinfo *ai)
{
struct addrinfo *next;
- do {
+ while (ai != NULL) {
next = ai->ai_next;
- if (ai->ai_canonname)
- free(ai->ai_canonname);
+ free(ai->ai_canonname);
/* no need to free(ai->ai_addr) */
free(ai);
ai = next;
- } while (ai);
+ }
}
static int
OpenPOWER on IntegriCloud