diff libpurple/protocols/yahoo/libymsg.c @ 31530:86598f5d7ebd

Yahoo: Fix a crash that happens when the PurpleAccount disconnects after purple_network_listen() is called in yahoo_send_p2p_pkt(), but before the callback for purple_network_listen() is called. This solution isn't perfect-- it will almost certainly fall flat on its face if yahoo_send_p2p_packet() is called twice in a row--but doesn't make matters worse. Fixes #12432. committer: John Bailey <rekkanoryo@rekkanoryo.org>
author hanzz@soc.pidgin.im
date Thu, 30 Dec 2010 01:22:52 +0000
parents 943fce8ef142
children a8cc50c2279f
line wrap: on
line diff
--- a/libpurple/protocols/yahoo/libymsg.c	Thu Dec 30 01:06:03 2010 +0000
+++ b/libpurple/protocols/yahoo/libymsg.c	Thu Dec 30 01:22:52 2010 +0000
@@ -2673,14 +2673,15 @@
 	if(!(p2p_data = data))
 		return ;
 
+	yd = p2p_data->gc->proto_data;
+	yd->listen_data = NULL;
+
 	if(listenfd == -1) {
 		purple_debug_warning("yahoo","p2p: error starting p2p server\n");
 		yahoo_p2p_disconnect_destroy_data(data);
 		return;
 	}
 
-	yd = p2p_data->gc->proto_data;
-
 	/* Add an Input Read event to the file descriptor */
 	yd->yahoo_local_p2p_server_fd = listenfd;
 	yd->yahoo_p2p_server_watcher = purple_input_add(listenfd, PURPLE_INPUT_READ, yahoo_p2p_server_send_connected_cb,data);
@@ -2759,8 +2760,15 @@
 	p2p_data->connection_type = YAHOO_P2P_WE_ARE_SERVER;
 	p2p_data->source = -1;
 
-	/* FIXME: Shouldn't this deal with the PurpleNetworkListenData* */
-	purple_network_listen(YAHOO_PAGER_PORT_P2P, SOCK_STREAM, yahoo_p2p_server_listen_cb, p2p_data);
+	/* FIXME: If the port is already used, purple_network_listener returns NULL and old listener won't be canceled
+	 * in yahoo_close function. */
+	if (yd->listen_data)
+		purple_debug_warning("yahoo","p2p: Failed to create p2p server - server already exists\n");
+	else {
+		yd->listen_data = purple_network_listen(YAHOO_PAGER_PORT_P2P, SOCK_STREAM, yahoo_p2p_server_listen_cb, p2p_data);
+		if (yd->listen_data == NULL)
+			purple_debug_warning("yahoo","p2p: Failed to created p2p server\n");
+	}
 
 	g_free(base64_ip);
 }
@@ -3784,6 +3792,8 @@
 		yahoo_buddy_icon_upload_data_free(yd->picture_upload_todo);
 	if (yd->ycht)
 		ycht_connection_close(yd->ycht);
+	if (yd->listen_data != NULL)
+		purple_network_listen_cancel(yd->listen_data);
 
 	g_free(yd->pending_chat_room);
 	g_free(yd->pending_chat_id);