pidgin: 177e6ef5: Make sure we keep track of this timer an...

markdoliner at pidgin.im markdoliner at pidgin.im
Tue Aug 10 03:04:26 EDT 2010


----------------------------------------------------------------------
Revision: 177e6ef54aafc14b79387d7bbfc3fbefce5983a2
Parent:   538d9a08724c2204939895c9dc03bb8b75986c88
Author:   markdoliner at pidgin.im
Date:     08/10/10 02:57:25
Branch:   im.pidgin.pidgin
URL: http://d.pidgin.im/viewmtn/revision/info/177e6ef54aafc14b79387d7bbfc3fbefce5983a2

Changelog: 

Make sure we keep track of this timer and remove it if our caller frees
listen_data before returning control to the mainloop.  I hit a crash
because of this.

Changes against parent 538d9a08724c2204939895c9dc03bb8b75986c88

  patched  libpurple/network.c

-------------- next part --------------
============================================================
--- libpurple/network.c	a1c5a75efbfba4fdf74b08087cb18a2971d1c021
+++ libpurple/network.c	8c70d2a63b2c464b174ff8cc768e43a6bff9c4cb
@@ -98,6 +98,7 @@ struct _PurpleNetworkListenData {
 	PurpleNetworkListenCallback cb;
 	gpointer cb_data;
 	UPnPMappingAddRemove *mapping_data;
+	int timer;
 };
 
 #ifdef HAVE_NETWORKMANAGER
@@ -373,6 +374,7 @@ purple_network_finish_pmp_map_cb(gpointe
 	gint *value = g_new(gint, 1);
 
 	listen_data = data;
+	listen_data->timer = 0;
 
 	/* add port mapping to hash table */
 	*key = purple_network_get_port_from_fd(listen_data->listenfd);
@@ -504,7 +506,7 @@ purple_network_do_listen(unsigned short 
 	{
 		purple_debug_info("network", "Skipping external port mapping.\n");
 		/* The pmp_map_cb does what we want to do */
-		purple_timeout_add(0, purple_network_finish_pmp_map_cb, listen_data);
+		listen_data->timer = purple_timeout_add(0, purple_network_finish_pmp_map_cb, listen_data);
 	}
 	/* Attempt a NAT-PMP Mapping, which will return immediately */
 	else if (purple_pmp_create_map(((socket_type == SOCK_STREAM) ? PURPLE_PMP_TYPE_TCP : PURPLE_PMP_TYPE_UDP),
@@ -512,7 +514,7 @@ purple_network_do_listen(unsigned short 
 	{
 		purple_debug_info("network", "Created NAT-PMP mapping on port %i\n", actual_port);
 		/* We want to return listen_data now, and on the next run loop trigger the cb and destroy listen_data */
-		purple_timeout_add(0, purple_network_finish_pmp_map_cb, listen_data);
+		listen_data->timer = purple_timeout_add(0, purple_network_finish_pmp_map_cb, listen_data);
 	}
 	else
 	{
@@ -584,6 +586,9 @@ void purple_network_listen_cancel(Purple
 	if (listen_data->mapping_data != NULL)
 		purple_upnp_cancel_port_mapping(listen_data->mapping_data);
 
+	if (listen_data->timer > 0)
+		purple_timeout_remove(listen_data->timer);
+
 	g_free(listen_data);
 }
 


More information about the Commits mailing list