pidgin: 568fccc3: Two SIMPLE changes:

markdoliner at pidgin.im markdoliner at pidgin.im
Mon Apr 12 03:15:44 EDT 2010


-----------------------------------------------------------------
Revision: 568fccc374c5310aa13839469fb3ca6339b94346
Ancestor: 262a8b23fdc8b8780c3c0c0ef61dcf9d4159e75f
Author: markdoliner at pidgin.im
Date: 2010-04-12T07:13:52
Branch: im.pidgin.pidgin
URL: http://d.pidgin.im/viewmtn/revision/info/568fccc374c5310aa13839469fb3ca6339b94346

Modified files:
        libpurple/protocols/simple/simple.c

ChangeLog: 

Two SIMPLE changes:
* Close the listener socket when disconnected.  Otherwise we leak the socket
  and eventually run out of sockets to listen on, because we listen on a range
  of 100 sockets
* Initialize the time_t before calling ctime

-------------- next part --------------
============================================================
--- libpurple/protocols/simple/simple.c	832cd403db6f793561d70a4ea6d8beae6331ef73
+++ libpurple/protocols/simple/simple.c	82905826ce43350183a7f6be10aa5fad1de18835
@@ -1663,7 +1663,7 @@ static void simple_udp_process(gpointer 
 	struct simple_account_data *sip = gc->proto_data;
 	struct sipmsg *msg;
 	int len;
-	time_t currtime;
+	time_t currtime = time(NULL);
 
 	static char buffer[65536];
 	if((len = recv(source, buffer, sizeof(buffer) - 1, 0)) > 0) {
@@ -1777,10 +1777,14 @@ static void simple_udp_host_resolved_lis
 		return;
 	}
 
+	/*
+	 * TODO: Is it correct to set sip->fd to the listenfd?  For the TCP
+	 *       listener we set sip->listenfd, but maybe UDP is different?
+	 *       Maybe we use the same fd for outgoing data or something?
+	 */
 	sip->fd = listenfd;
 
 	sip->listenport = purple_network_get_port_from_fd(sip->fd);
-	sip->listenfd = sip->fd;
 
 	sip->listenpa = purple_input_add(sip->fd, PURPLE_INPUT_READ, simple_udp_process, sip->gc);
 
@@ -1982,6 +1986,14 @@ static void simple_close(PurpleConnectio
 	}
 	connection_free_all(sip);
 
+	if (sip->listenpa)
+		purple_input_remove(sip->listenpa);
+	if (sip->tx_handler)
+		purple_input_remove(sip->tx_handler);
+	if (sip->resendtimeout)
+		purple_timeout_remove(sip->resendtimeout);
+	if (sip->registertimeout)
+		purple_timeout_remove(sip->registertimeout);
 	if (sip->query_data != NULL)
 		purple_dnsquery_destroy(sip->query_data);
 
@@ -1991,6 +2003,11 @@ static void simple_close(PurpleConnectio
 	if (sip->listen_data != NULL)
 		purple_network_listen_cancel(sip->listen_data);
 
+	if (sip->fd >= 0)
+		close(sip->fd);
+	if (sip->listenfd >= 0)
+		close(sip->listenfd);
+
 	g_free(sip->servername);
 	g_free(sip->username);
 	g_free(sip->password);
@@ -2008,14 +2025,6 @@ static void simple_close(PurpleConnectio
 	if (sip->txbuf)
 		purple_circ_buffer_destroy(sip->txbuf);
 	g_free(sip->realhostname);
-	if (sip->listenpa)
-		purple_input_remove(sip->listenpa);
-	if (sip->tx_handler)
-		purple_input_remove(sip->tx_handler);
-	if (sip->resendtimeout)
-		purple_timeout_remove(sip->resendtimeout);
-	if (sip->registertimeout)
-		purple_timeout_remove(sip->registertimeout);
 
 	g_free(sip);
 	gc->proto_data = NULL;


More information about the Commits mailing list