# HG changeset patch # User Sulabh Mahajan # Date 1213355053 0 # Node ID 11e2d8a878b042430a2c3a041c7386cd74c76c9d # Parent ef47df3e5dd477d3553ace888d8ec0040f7d9228 Close p2p connection when read() does not return anything. diff -r ef47df3e5dd4 -r 11e2d8a878b0 libpurple/protocols/yahoo/yahoo.c --- a/libpurple/protocols/yahoo/yahoo.c Mon Jun 09 08:08:21 2008 +0000 +++ b/libpurple/protocols/yahoo/yahoo.c Fri Jun 13 11:04:13 2008 +0000 @@ -246,7 +246,7 @@ if (f->away == 2) { /* Idle may have already been set in a more precise way in case 137 */ if (f->idle == 0) - f->idle = time(NULL); + f->idle = time(NULL) - 60; /*start idle at 1 min*/ } break; @@ -2296,13 +2296,22 @@ guchar *start = NULL; struct yahoo_p2p_data *user_data; - user_data = data; - - if((len = read(source, buf, sizeof(buf))) <= 0 ) - purple_debug_warning("yahoo","p2p: Error in connection to p2p host\n"); + if(!(user_data = data)) + return ; + + if((len = read(source, buf, sizeof(buf))) <= 0 ) { + purple_debug_warning("yahoo","p2p: Error in connection to p2p host or host disconnected\n"); + purple_input_remove(user_data->input_event); + close(source); + /*free user data*/ + g_free(user_data->host_ip); + g_free(user_data->host_username); + g_free(user_data); + } if(len < YAHOO_PACKET_HDRLEN) return; + if(strncmp((char *)buf, "YMSG", MIN(4, len)) != 0) { /* Not a YMSG packet */ purple_debug_warning("yahoo","p2p: Got something other than YMSG packet\n"); @@ -2361,12 +2370,12 @@ purple_debug_warning("yahoo","p2p: %s\n",error_message); return; } - /*Add an Input Read event to the file descriptor*/ - purple_input_add(source, PURPLE_INPUT_READ, yahoo_p2p_read_pkt_cb, data); - if(!(user_data = data)) return ; + /*Add an Input Read event to the file descriptor*/ + user_data->input_event = purple_input_add(source, PURPLE_INPUT_READ, yahoo_p2p_read_pkt_cb, data); + account = purple_connection_get_account(user_data->gc); /*Build the yahoo packet*/ diff -r ef47df3e5dd4 -r 11e2d8a878b0 libpurple/protocols/yahoo/yahoo.h --- a/libpurple/protocols/yahoo/yahoo.h Mon Jun 09 08:08:21 2008 +0000 +++ b/libpurple/protocols/yahoo/yahoo.h Fri Jun 13 11:04:13 2008 +0000 @@ -120,6 +120,7 @@ int session_id; char *host_username; int val_13; + guint input_event; }; struct _YchtConn;