ares.h: there is no ares_free_soa function
[platform/upstream/c-ares.git] / ares_free_hostent.c
index b33064e..7f44882 100644 (file)
@@ -1,3 +1,4 @@
+
 /* Copyright 1998 by the Massachusetts Institute of Technology.
  *
  * Permission to use, copy, modify, and distribute this
  * without express or implied warranty.
  */
 
-#include "setup.h"
-#include <stdlib.h>
-
-#ifdef WIN32
+#include "ares_setup.h"
 
-#else
+#ifdef HAVE_NETDB_H
 #include <netdb.h>
 #endif
 
@@ -29,11 +27,15 @@ void ares_free_hostent(struct hostent *host)
 {
   char **p;
 
-  free(host->h_name);
+  if (!host)
+    return;
+
+  free((char *)(host->h_name));
   for (p = host->h_aliases; *p; p++)
     free(*p);
   free(host->h_aliases);
-  free(host->h_addr_list[0]);
+  free(host->h_addr_list[0]); /* no matter if there is one or many entries,
+                                 there is only one malloc for all of them */
   free(host->h_addr_list);
   free(host);
 }