changeset 14358:fdf65b672b87

[gaim-migrate @ 17064] Fix a small memleak committer: Tailor Script <tailor@pidgin.im>
author Mark Doliner <mark@kingant.net>
date Sun, 27 Aug 2006 22:04:09 +0000
parents 4e14503b9bac
children 114e692e08fb
files libgaim/dnsquery.c
diffstat 1 files changed, 17 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/libgaim/dnsquery.c	Sun Aug 27 21:36:52 2006 +0000
+++ b/libgaim/dnsquery.c	Sun Aug 27 22:04:09 2006 +0000
@@ -87,6 +87,21 @@
 	gaim_debug_info("dnsquery", "IP resolved for %s\n", query_data->hostname);
 	if (query_data->callback != NULL)
 		query_data->callback(hosts, query_data->data, NULL);
+	else
+	{
+		/*
+		 * Callback is a required parameter, but it can get set to
+		 * NULL if we cancel a thread-based DNS lookup.  So we need
+		 * to free hosts.
+		 */
+		while (hosts != NULL)
+		{
+			hosts = g_slist_remove(hosts, hosts->data);
+			g_free(hosts->data);
+			hosts = g_slist_remove(hosts, hosts->data);
+		}
+	}
+
 	gaim_dnsquery_destroy(query_data);
 }
 
@@ -566,6 +581,7 @@
 
 	g_return_val_if_fail(hostname != NULL, NULL);
 	g_return_val_if_fail(port     != 0, NULL);
+	g_return_val_if_fail(callback != NULL, NULL);
 
 	query_data = g_new(GaimDnsQueryData, 1);
 	query_data->hostname = g_strdup(hostname);
@@ -728,6 +744,7 @@
 
 	g_return_val_if_fail(hostname != NULL, NULL);
 	g_return_val_if_fail(port     != 0, NULL);
+	g_return_val_if_fail(callback != NULL, NULL);
 
 	gaim_debug_info("dnsquery", "Performing DNS lookup for %s\n", hostname);