/pidgin/main: 53c9ebedf2b7: Plug g_resolver_get_default() leaks

Mike Ruprecht cmaiku at gmail.com
Sat Jan 9 11:37:00 EST 2016


Changeset: 53c9ebedf2b785f8e22444c4c00be97318329ffb
Author:	 Mike Ruprecht <cmaiku at gmail.com>
Date:	 2016-01-07 21:06 -0600
Branch:	 default
URL: https://hg.pidgin.im/pidgin/main/rev/53c9ebedf2b7

Description:

Plug g_resolver_get_default() leaks

g_resolver_get_default() returns a new reference to the default
GResolver. The g_resolver_lookup_*_async() functions hold onto
an additional reference during their lookup operations. Therefore
this patch unrefs the GResolver right after the
g_resolver_lookup_*_async() functions are called.

diffstat:

 libpurple/network.c                            |   8 ++++++--
 libpurple/protocols/gg/resolver-purple.c       |   6 +++++-
 libpurple/protocols/jabber/disco.c             |   4 +++-
 libpurple/protocols/jabber/google/jingleinfo.c |   5 ++++-
 libpurple/protocols/jabber/jabber.c            |   8 ++++++--
 libpurple/protocols/simple/simple.c            |  12 +++++++++---
 libpurple/protocols/yahoo/yahoo_filexfer.c     |   5 ++++-
 libpurple/proxy.c                              |  10 ++++++++--
 libpurple/stun.c                               |  10 ++++++++--
 9 files changed, 53 insertions(+), 15 deletions(-)

diffs (truncated from 317 to 300 lines):

diff --git a/libpurple/network.c b/libpurple/network.c
--- a/libpurple/network.c
+++ b/libpurple/network.c
@@ -599,11 +599,13 @@ purple_network_set_stun_server(const gch
 {
 	if (stun_server && stun_server[0] != '\0') {
 		if (purple_network_is_available()) {
-			g_resolver_lookup_by_name_async(g_resolver_get_default(),
+			GResolver *resolver = g_resolver_get_default();
+			g_resolver_lookup_by_name_async(resolver,
 			                                stun_server,
 			                                NULL,
 			                                purple_network_ip_lookup_cb,
 			                                &stun_ip);
+			g_object_unref(resolver);
 		} else {
 			purple_debug_info("network",
 				"network is unavailable, don't try to update STUN IP");
@@ -619,11 +621,13 @@ purple_network_set_turn_server(const gch
 {
 	if (turn_server && turn_server[0] != '\0') {
 		if (purple_network_is_available()) {
-			g_resolver_lookup_by_name_async(g_resolver_get_default(),
+			GResolver *resolver = g_resolver_get_default();
+			g_resolver_lookup_by_name_async(resolver,
 			                                turn_server,
 			                                NULL,
 			                                purple_network_ip_lookup_cb,
 			                                &turn_server);
+			g_object_unref(resolver);
 		} else {
 			purple_debug_info("network",
 				"network is unavailable, don't try to update TURN IP");
diff --git a/libpurple/protocols/gg/resolver-purple.c b/libpurple/protocols/gg/resolver-purple.c
--- a/libpurple/protocols/gg/resolver-purple.c
+++ b/libpurple/protocols/gg/resolver-purple.c
@@ -137,6 +137,8 @@ int ggp_resolver_purple_start(int *fd, v
 	const char *hostname)
 {
 	ggp_resolver_purple_data *data;
+	GResolver *resolver;
+
 	purple_debug_misc("gg", "ggp_resolver_purple_start(%p, %p, \"%s\")\n",
 		fd, private_data, hostname);
 
@@ -158,11 +160,13 @@ int ggp_resolver_purple_start(int *fd, v
 	/* account and port is unknown in this context */
 	data->cancellable = g_cancellable_new();
 
-	g_resolver_lookup_by_name_async(g_resolver_get_default(),
+	resolver = g_resolver_get_default();
+	g_resolver_lookup_by_name_async(resolver,
 	                                hostname,
 	                                data->cancellable,
 	                                ggp_resolver_purple_cb,
 	                                (gpointer)data);
+	g_object_unref(resolver);
 
 	if (!data->cancellable) {
 		purple_debug_error("gg", "ggp_resolver_purple_start: "
diff --git a/libpurple/protocols/jabber/disco.c b/libpurple/protocols/jabber/disco.c
--- a/libpurple/protocols/jabber/disco.c
+++ b/libpurple/protocols/jabber/disco.c
@@ -517,13 +517,15 @@ jabber_disco_server_info_result_cb(Jabbe
 		} else if (purple_network_get_stun_ip() == NULL ||
 		    purple_strequal(purple_network_get_stun_ip(), "")) {
 
-			g_resolver_lookup_service_async(g_resolver_get_default(),
+			GResolver *resolver = g_resolver_get_default();
+			g_resolver_lookup_service_async(resolver,
 			                                "stun",
 			                                "udp",
 			                                js->user->domain,
 			                                NULL,
 			                                jabber_disco_stun_srv_resolve_cb,
 			                                js);
+			g_object_unref(resolver);
 			/* TODO: add TURN support later... */
 		}
 	}
diff --git a/libpurple/protocols/jabber/google/jingleinfo.c b/libpurple/protocols/jabber/google/jingleinfo.c
--- a/libpurple/protocols/jabber/google/jingleinfo.c
+++ b/libpurple/protocols/jabber/google/jingleinfo.c
@@ -93,13 +93,16 @@ jabber_google_jingle_info_common(JabberS
 			const gchar *udp = purple_xmlnode_get_attrib(server, "udp");
 
 			if (host && udp) {
+				GResolver *resolver = g_resolver_get_default();
+
 				js->stun_port = atoi(udp);
 
-				g_resolver_lookup_by_name_async(g_resolver_get_default(),
+				g_resolver_lookup_by_name_async(resolver,
 				                                host,
 				                                NULL,
 				                                jabber_google_stun_lookup_cb,
 				                                js);
+				g_object_unref(resolver);
 			}
 		}
 	}
diff --git a/libpurple/protocols/jabber/jabber.c b/libpurple/protocols/jabber/jabber.c
--- a/libpurple/protocols/jabber/jabber.c
+++ b/libpurple/protocols/jabber/jabber.c
@@ -825,17 +825,19 @@ jabber_login_callback(gpointer data, gin
 	JabberStream *js = purple_connection_get_protocol_data(gc);
 
 	if (source < 0) {
+		GResolver *resolver = g_resolver_get_default();
 		gchar *name = g_strdup_printf("_xmppconnect.%s", js->user->domain);
 
 		purple_debug_info("jabber", "Couldn't connect directly to %s.  Trying to find alternative connection methods, like BOSH.\n", js->user->domain);
 
-		g_resolver_lookup_records_async(g_resolver_get_default(),
+		g_resolver_lookup_records_async(resolver,
 		                                name,
 		                                G_RESOLVER_RECORD_TXT,
 		                                js->cancellable,
 		                                txt_resolved_cb,
 		                                js);
 		g_free(name);
+		g_object_unref(resolver);
 
 		return;
 	}
@@ -1091,13 +1093,15 @@ jabber_stream_connect(JabberStream *js)
 		jabber_login_connect(js, js->user->domain, connect_server,
 				purple_account_get_int(account, "port", 5222), TRUE);
 	} else {
-		g_resolver_lookup_service_async(g_resolver_get_default(),
+		GResolver *resolver = g_resolver_get_default();
+		g_resolver_lookup_service_async(resolver,
 		                                "xmpp-client",
 		                                "tcp",
 		                                js->user->domain,
 		                                js->cancellable,
 		                                srv_resolved_cb,
 		                                js);
+		g_object_unref(resolver);
 	}
 }
 
diff --git a/libpurple/protocols/simple/simple.c b/libpurple/protocols/simple/simple.c
--- a/libpurple/protocols/simple/simple.c
+++ b/libpurple/protocols/simple/simple.c
@@ -1928,13 +1928,16 @@ srvresolved(GObject *sender, GAsyncResul
 			return;
 		}
 	} else { /* UDP */
+		GResolver *resolver = g_resolver_get_default();
+
 		purple_debug_info("simple", "using udp with server %s and port %d\n", hostname, port);
 
-		g_resolver_lookup_by_name_async(g_resolver_get_default(),
+		g_resolver_lookup_by_name_async(resolver,
 		                                sip->realhostname,
 		                                sip->cancellable,
 		                                simple_udp_host_resolved,
 		                                sip);
+		g_object_unref(resolver);
 	}
 }
 
@@ -1944,8 +1947,9 @@ static void simple_login(PurpleAccount *
 	struct simple_account_data *sip;
 	gchar **userserver;
 	const gchar *hosttoconnect;
+	const char *username = purple_account_get_username(account);
+	GResolver *resolver;
 
-	const char *username = purple_account_get_username(account);
 	gc = purple_account_get_connection(account);
 
 	purple_connection_set_flags(gc, PURPLE_CONNECTION_FLAG_NO_IMAGES);
@@ -1996,13 +2000,15 @@ static void simple_login(PurpleAccount *
 		hosttoconnect = purple_account_get_string(account, "proxy", sip->servername);
 	}
 
-	g_resolver_lookup_service_async(g_resolver_get_default(),
+	resolver = g_resolver_get_default();
+	g_resolver_lookup_service_async(resolver,
 	                                "sip",
 	                                sip->udp ? "udp" : "tcp",
 	                                hosttoconnect,
 	                                sip->cancellable,
 	                                srvresolved,
 	                                sip);
+	g_object_unref(resolver);
 }
 
 static void simple_close(PurpleConnection *gc)
diff --git a/libpurple/protocols/yahoo/yahoo_filexfer.c b/libpurple/protocols/yahoo/yahoo_filexfer.c
--- a/libpurple/protocols/yahoo/yahoo_filexfer.c
+++ b/libpurple/protocols/yahoo/yahoo_filexfer.c
@@ -679,6 +679,7 @@ void yahoo_process_filetrans_15(PurpleCo
 	if(val_222 == 3)
 	{
 		struct yahoo_xfer_data *xd;
+		GResolver *resolver;
 
 		xfer = g_hash_table_lookup(yd->xfer_peer_idstring_map,
 								   xfer_peer_idstring);
@@ -703,11 +704,13 @@ void yahoo_process_filetrans_15(PurpleCo
 		}
 		xd->is_relay = TRUE;
 
-		g_resolver_lookup_by_name_async(g_resolver_get_default(),
+		resolver = g_resolver_get_default();
+		g_resolver_lookup_by_name_async(resolver,
 		                                YAHOO_XFER_RELAY_HOST,
 		                                NULL,
 		                                yahoo_xfer_dns_connected_15,
 		                                xfer);
+		g_object_unref(resolver);
 
 		return;
 	}
diff --git a/libpurple/proxy.c b/libpurple/proxy.c
--- a/libpurple/proxy.c
+++ b/libpurple/proxy.c
@@ -2338,6 +2338,7 @@ purple_proxy_connect(void *handle, Purpl
 	const char *connecthost = host;
 	int connectport = port;
 	PurpleProxyConnectData *connect_data;
+	GResolver *resolver;
 
 	g_return_val_if_fail(host       != NULL, NULL);
 	g_return_val_if_fail(port       >  0,    NULL);
@@ -2389,11 +2390,13 @@ purple_proxy_connect(void *handle, Purpl
 
 	connect_data->cancellable = g_cancellable_new();
 
-	g_resolver_lookup_by_name_async(g_resolver_get_default(),
+	resolver = g_resolver_get_default();
+	g_resolver_lookup_by_name_async(resolver,
 	                                connecthost,
 	                                connect_data->cancellable,
 	                                connection_host_resolved,
 	                                connect_data);
+	g_object_unref(resolver);
 
 	if (connect_data->cancellable == NULL)
 	{
@@ -2415,6 +2418,7 @@ purple_proxy_connect_udp(void *handle, P
 	const char *connecthost = host;
 	int connectport = port;
 	PurpleProxyConnectData *connect_data;
+	GResolver *resolver;
 
 	g_return_val_if_fail(host       != NULL, NULL);
 	g_return_val_if_fail(port       >  0,    NULL);
@@ -2466,11 +2470,13 @@ purple_proxy_connect_udp(void *handle, P
 
 	connect_data->cancellable = g_cancellable_new();
 
-	g_resolver_lookup_by_name_async(g_resolver_get_default(),
+	resolver = g_resolver_get_default();
+	g_resolver_lookup_by_name_async(resolver,
 	                                connecthost,
 	                                connect_data->cancellable,
 	                                connection_host_resolved,
 	                                connect_data);
+	g_object_unref(resolver);
 
 	if (connect_data->cancellable == NULL) {
 		purple_proxy_connect_data_destroy(connect_data);
diff --git a/libpurple/stun.c b/libpurple/stun.c
--- a/libpurple/stun.c
+++ b/libpurple/stun.c
@@ -377,6 +377,7 @@ static void
 do_test1(GObject *sender, GAsyncResult *res, gpointer data) {
 	GList *services = NULL;
 	GError *error = NULL;
+	GResolver *resolver;
 	const char *servername = data;
 	int port = 3478;
 
@@ -393,11 +394,13 @@ do_test1(GObject *sender, GAsyncResult *
 
 	purple_debug_info("stun", "connecting to %s:%d\n", servername, port);
 
-	g_resolver_lookup_by_name_async(g_resolver_get_default(),
+	resolver = g_resolver_get_default();
+	g_resolver_lookup_by_name_async(resolver,
 	                                servername,
 	                                NULL,
 	                                hbn_cb,
 	                                GINT_TO_POINTER(port));
+	g_object_unref(resolver);
 
 	g_resolver_free_targets(services);
 }
@@ -410,6 +413,7 @@ static gboolean call_callback(gpointer d
 
 PurpleStunNatDiscovery *purple_stun_discover(PurpleStunCallback cb) {
 	const char *servername = purple_prefs_get_string("/purple/network/stun_server");
+	GResolver *resolver;
 
 	purple_debug_info("stun", "using server %s\n", servername);
 



More information about the Commits mailing list