1 2 /* Copyright 1998 by the Massachusetts Institute of Technology. 3 * Copyright (C) 2019 by Andrew Selivanov 4 * 5 * Permission to use, copy, modify, and distribute this 6 * software and its documentation for any purpose and without 7 * fee is hereby granted, provided that the above copyright 8 * notice appear in all copies and that both that copyright 9 * notice and this permission notice appear in supporting 10 * documentation, and that the name of M.I.T. not be used in 11 * advertising or publicity pertaining to distribution of the 12 * software without specific, written prior permission. 13 * M.I.T. makes no representations about the suitability of 14 * this software for any purpose. It is provided "as is" 15 * without express or implied warranty. 16 */ 17 18 #include "ares_setup.h" 19 20 #ifdef HAVE_NETDB_H 21 # include <netdb.h> 22 #endif 23 24 #include "ares.h" 25 #include "ares_private.h" 26 ares__freeaddrinfo_cnames(struct ares_addrinfo_cname * head)27void ares__freeaddrinfo_cnames(struct ares_addrinfo_cname *head) 28 { 29 struct ares_addrinfo_cname *current; 30 while (head) 31 { 32 current = head; 33 head = head->next; 34 ares_free(current->alias); 35 ares_free(current->name); 36 ares_free(current); 37 } 38 } 39 ares__freeaddrinfo_nodes(struct ares_addrinfo_node * head)40void ares__freeaddrinfo_nodes(struct ares_addrinfo_node *head) 41 { 42 struct ares_addrinfo_node *current; 43 while (head) 44 { 45 current = head; 46 head = head->ai_next; 47 ares_free(current->ai_addr); 48 ares_free(current); 49 } 50 } 51 ares_freeaddrinfo(struct ares_addrinfo * ai)52void ares_freeaddrinfo(struct ares_addrinfo *ai) 53 { 54 if (ai == NULL) 55 return; 56 ares__freeaddrinfo_cnames(ai->cnames); 57 ares__freeaddrinfo_nodes(ai->nodes); 58 ares_free(ai->name); 59 ares_free(ai); 60 } 61