From c62a4b5a7aede760b06298f4b641b5a9768f5744 Mon Sep 17 00:00:00 2001 From: Elliott Hughes Date: Thu, 8 Jan 2015 17:28:46 -0800 Subject: [PATCH] Fix freeaddrinfo(NULL). Bug: https://code.google.com/p/android/issues/detail?id=13228 Change-Id: I5e3b126d90d750a93ac0b8872198e50ba047e603 --- libc/dns/net/getaddrinfo.c | 6 +++++- tests/netdb_test.cpp | 5 +++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/libc/dns/net/getaddrinfo.c b/libc/dns/net/getaddrinfo.c index f0d522a02..c73c08521 100644 --- a/libc/dns/net/getaddrinfo.c +++ b/libc/dns/net/getaddrinfo.c @@ -324,7 +324,11 @@ freeaddrinfo(struct addrinfo *ai) { struct addrinfo *next; - assert(ai != NULL); +#if __ANDROID__ + if (ai == NULL) return; +#else + _DIAGASSERT(ai != NULL); +#endif do { next = ai->ai_next; diff --git a/tests/netdb_test.cpp b/tests/netdb_test.cpp index ab5b48755..5660bbdaa 100644 --- a/tests/netdb_test.cpp +++ b/tests/netdb_test.cpp @@ -23,6 +23,11 @@ #include #include +// https://code.google.com/p/android/issues/detail?id=13228 +TEST(netdb, freeaddrinfo_NULL) { + freeaddrinfo(NULL); +} + TEST(netdb, getaddrinfo_NULL_host) { // It's okay for the host argument to be NULL, as long as service isn't. addrinfo* ai = NULL;