# HG changeset patch # User Evan Schoenberg # Date 1199255795 0 # Node ID eaaac273d80ccd8a2988b02c2d0f152b70501b36 # Parent 02153fd5a09261ea45cbeb7042467165f8de5724 Keep track of the keepalive timeout source so it can be removed when the account disconnects. This prevents a possible crash if the timeout fired after the account disconnected. diff -r 02153fd5a092 -r eaaac273d80c libpurple/protocols/jabber/jabber.c --- a/libpurple/protocols/jabber/jabber.c Sun Dec 30 10:07:50 2007 +0000 +++ b/libpurple/protocols/jabber/jabber.c Wed Jan 02 06:36:35 2008 +0000 @@ -391,25 +391,27 @@ static void jabber_pong_cb(JabberStream *js, xmlnode *packet, gpointer timeout) { purple_timeout_remove(GPOINTER_TO_INT(timeout)); + js->keepalive_timeout = -1; } static gboolean jabber_pong_timeout(PurpleConnection *gc) { purple_connection_error_reason(gc, PURPLE_CONNECTION_ERROR_NETWORK_ERROR, _("Ping timeout")); + js->keepalive_timeout = -1; return FALSE; } void jabber_keepalive(PurpleConnection *gc) { - JabberIq *iq = jabber_iq_new(gc->proto_data, JABBER_IQ_GET); - guint timeout; + JabberStream *js = gc->proto_data; + JabberIq *iq = jabber_iq_new(js, JABBER_IQ_GET); - xmlnode *ping = xmlnode_new_child(iq->node, "ping"); - xmlnode_set_namespace(ping, "urn:xmpp:ping"); + xmlnode *ping = xmlnode_new_child(iq->node, "ping"); + xmlnode_set_namespace(ping, "urn:xmpp:ping"); - timeout = purple_timeout_add_seconds(20, (GSourceFunc)(jabber_pong_timeout), gc); - jabber_iq_set_callback(iq, jabber_pong_cb, GINT_TO_POINTER(timeout)); + js->keepalive_timeout = purple_timeout_add_seconds(20, (GSourceFunc)(jabber_pong_timeout), gc); + jabber_iq_set_callback(iq, jabber_pong_cb, GINT_TO_POINTER(js->keepalive_timeout)); jabber_iq_send(iq); } @@ -612,6 +614,7 @@ js->next_id = g_random_int(); js->write_buffer = purple_circ_buffer_new(512); js->old_length = -1; + js->keepalive_timeout = -1; if(!js->user) { purple_connection_error_reason (gc, @@ -1311,6 +1314,9 @@ g_free(js->old_uri); g_free(js->old_track); + if (js->keepalive_timeout != -1) + purple_timeout_remove(js->keepalive_timeout); + g_free(js); gc->proto_data = NULL; diff -r 02153fd5a092 -r eaaac273d80c libpurple/protocols/jabber/jabber.h --- a/libpurple/protocols/jabber/jabber.h Sun Dec 30 10:07:50 2007 +0000 +++ b/libpurple/protocols/jabber/jabber.h Wed Jan 02 06:36:35 2008 +0000 @@ -193,6 +193,9 @@ char *old_track; char *host; + + /* A purple timeout tag for the keepalive */ + int keepalive_timeout; }; typedef gboolean (JabberFeatureEnabled)(JabberStream *js, const gchar *shortname, const gchar *namespace);