Mercurial > pidgin.yaz
comparison libpurple/network.c @ 30777:c91976cf319c
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.
author | Mark Doliner <mark@kingant.net> |
---|---|
date | Tue, 10 Aug 2010 06:57:25 +0000 |
parents | 35a1cf247168 |
children | 603638fad2f1 |
comparison
equal
deleted
inserted
replaced
30775:7460ab6199fe | 30777:c91976cf319c |
---|---|
96 gboolean retry; | 96 gboolean retry; |
97 gboolean adding; | 97 gboolean adding; |
98 PurpleNetworkListenCallback cb; | 98 PurpleNetworkListenCallback cb; |
99 gpointer cb_data; | 99 gpointer cb_data; |
100 UPnPMappingAddRemove *mapping_data; | 100 UPnPMappingAddRemove *mapping_data; |
101 int timer; | |
101 }; | 102 }; |
102 | 103 |
103 #ifdef HAVE_NETWORKMANAGER | 104 #ifdef HAVE_NETWORKMANAGER |
104 static NMState nm_get_network_state(void); | 105 static NMState nm_get_network_state(void); |
105 #endif | 106 #endif |
371 PurpleNetworkListenData *listen_data; | 372 PurpleNetworkListenData *listen_data; |
372 gint *key = g_new(gint, 1); | 373 gint *key = g_new(gint, 1); |
373 gint *value = g_new(gint, 1); | 374 gint *value = g_new(gint, 1); |
374 | 375 |
375 listen_data = data; | 376 listen_data = data; |
377 listen_data->timer = 0; | |
376 | 378 |
377 /* add port mapping to hash table */ | 379 /* add port mapping to hash table */ |
378 *key = purple_network_get_port_from_fd(listen_data->listenfd); | 380 *key = purple_network_get_port_from_fd(listen_data->listenfd); |
379 *value = listen_data->socket_type; | 381 *value = listen_data->socket_type; |
380 g_hash_table_insert(nat_pmp_port_mappings, key, value); | 382 g_hash_table_insert(nat_pmp_port_mappings, key, value); |
502 if (!purple_socket_speaks_ipv4(listenfd) || !listen_map_external || | 504 if (!purple_socket_speaks_ipv4(listenfd) || !listen_map_external || |
503 !purple_prefs_get_bool("/purple/network/map_ports")) | 505 !purple_prefs_get_bool("/purple/network/map_ports")) |
504 { | 506 { |
505 purple_debug_info("network", "Skipping external port mapping.\n"); | 507 purple_debug_info("network", "Skipping external port mapping.\n"); |
506 /* The pmp_map_cb does what we want to do */ | 508 /* The pmp_map_cb does what we want to do */ |
507 purple_timeout_add(0, purple_network_finish_pmp_map_cb, listen_data); | 509 listen_data->timer = purple_timeout_add(0, purple_network_finish_pmp_map_cb, listen_data); |
508 } | 510 } |
509 /* Attempt a NAT-PMP Mapping, which will return immediately */ | 511 /* Attempt a NAT-PMP Mapping, which will return immediately */ |
510 else if (purple_pmp_create_map(((socket_type == SOCK_STREAM) ? PURPLE_PMP_TYPE_TCP : PURPLE_PMP_TYPE_UDP), | 512 else if (purple_pmp_create_map(((socket_type == SOCK_STREAM) ? PURPLE_PMP_TYPE_TCP : PURPLE_PMP_TYPE_UDP), |
511 actual_port, actual_port, PURPLE_PMP_LIFETIME)) | 513 actual_port, actual_port, PURPLE_PMP_LIFETIME)) |
512 { | 514 { |
513 purple_debug_info("network", "Created NAT-PMP mapping on port %i\n", actual_port); | 515 purple_debug_info("network", "Created NAT-PMP mapping on port %i\n", actual_port); |
514 /* We want to return listen_data now, and on the next run loop trigger the cb and destroy listen_data */ | 516 /* We want to return listen_data now, and on the next run loop trigger the cb and destroy listen_data */ |
515 purple_timeout_add(0, purple_network_finish_pmp_map_cb, listen_data); | 517 listen_data->timer = purple_timeout_add(0, purple_network_finish_pmp_map_cb, listen_data); |
516 } | 518 } |
517 else | 519 else |
518 { | 520 { |
519 /* Attempt a UPnP Mapping */ | 521 /* Attempt a UPnP Mapping */ |
520 listen_data->mapping_data = purple_upnp_set_port_mapping( | 522 listen_data->mapping_data = purple_upnp_set_port_mapping( |
581 | 583 |
582 void purple_network_listen_cancel(PurpleNetworkListenData *listen_data) | 584 void purple_network_listen_cancel(PurpleNetworkListenData *listen_data) |
583 { | 585 { |
584 if (listen_data->mapping_data != NULL) | 586 if (listen_data->mapping_data != NULL) |
585 purple_upnp_cancel_port_mapping(listen_data->mapping_data); | 587 purple_upnp_cancel_port_mapping(listen_data->mapping_data); |
588 | |
589 if (listen_data->timer > 0) | |
590 purple_timeout_remove(listen_data->timer); | |
586 | 591 |
587 g_free(listen_data); | 592 g_free(listen_data); |
588 } | 593 } |
589 | 594 |
590 unsigned short | 595 unsigned short |