diff options
author | Mark Doliner <markdoliner@pidgin.im> | 2010-08-10 06:57:25 +0000 |
---|---|---|
committer | Mark Doliner <markdoliner@pidgin.im> | 2010-08-10 06:57:25 +0000 |
commit | 45552dc76bd673efb97cdc7fcbaaaf092ab78c27 (patch) | |
tree | 06a3e05689a071b892eb8989415f533d62be319a /libpurple | |
parent | 94befdb45a6296354d3d523efb1c24c7004071c8 (diff) | |
download | pidgin-45552dc76bd673efb97cdc7fcbaaaf092ab78c27.tar.gz |
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.
Diffstat (limited to 'libpurple')
-rw-r--r-- | libpurple/network.c | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/libpurple/network.c b/libpurple/network.c index 0d3a600a77..0ceff6509f 100644 --- a/libpurple/network.c +++ b/libpurple/network.c @@ -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(gpointer data) 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 port, int socket_family, int socket_type { 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 port, int socket_family, int socket_type { 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(PurpleNetworkListenData *listen_data) 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); } |