Index: lib/oauth.c
===================================================================
--- lib/oauth.c	(revision e1c926f53750ca288f30f3d62eecdc763b67d642)
+++ lib/oauth.c	(revision f138bd25e9184c3033f405a7bbb5734d82a877c7)
@@ -122,4 +122,7 @@
 	char *item;
 	
+	if( !key || !value )
+		return;
+	
 	item = g_strdup_printf( "%s=%s", key, value );
 	*params = g_slist_insert_sorted( *params, item, (GCompareFunc) strcmp );
Index: protocols/jabber/jabber.c
===================================================================
--- protocols/jabber/jabber.c	(revision e1c926f53750ca288f30f3d62eecdc763b67d642)
+++ protocols/jabber/jabber.c	(revision f138bd25e9184c3033f405a7bbb5734d82a877c7)
@@ -140,4 +140,6 @@
 	if( set_getbool( &acc->set, "oauth" ) )
 	{
+		jd->fd = jd->r_inpa = jd->w_inpa = -1;
+		
 		/* For the first login with OAuth, we have to authenticate via the browser.
 		   For subsequent logins, exchange the refresh token for a valid access
@@ -285,4 +287,5 @@
 	xt_free( jd->xt );
 	
+	g_free( jd->oauth2_access_token );
 	g_free( jd->away_message );
 	g_free( jd->username );
Index: protocols/jabber/sasl.c
===================================================================
--- protocols/jabber/sasl.c	(revision e1c926f53750ca288f30f3d62eecdc763b67d642)
+++ protocols/jabber/sasl.c	(revision f138bd25e9184c3033f405a7bbb5734d82a877c7)
@@ -234,10 +234,10 @@
 	struct im_connection *ic = data;
 	struct jabber_data *jd = ic->proto_data;
-	struct xt_node *reply = NULL;
+	struct xt_node *reply_pkt = NULL;
 	char *nonce = NULL, *realm = NULL, *cnonce = NULL;
 	unsigned char cnonce_bin[30];
 	char *digest_uri = NULL;
 	char *dec = NULL;
-	char *s = NULL;
+	char *s = NULL, *reply = NULL;
 	xt_status ret = XT_ABORT;
 	
@@ -249,7 +249,13 @@
 	if( jd->flags & JFLAG_SASL_FB )
 	{
+		/* Facebook proprietary authentication. Not as useful as it seemed, but
+		   the code's written now, may as well keep it..
+		   
+		   Mechanism is described on http://developers.facebook.com/docs/chat/
+		   and in their Python module. It's all mostly useless because the tokens
+		   expire after 24h. */
 		GSList *p_in = NULL, *p_out = NULL, *p;
 		md5_state_t md5;
-		char time[33], *fmt, *token;
+		char time[33], *token;
 		const char *secret;
 		
@@ -275,13 +281,12 @@
 		
 		secret = oauth_params_get( &p_in, "secret" );
-		md5_append( &md5, (unsigned char*) secret, strlen( secret ) );
+		if( secret )
+			md5_append( &md5, (unsigned char*) secret, strlen( secret ) );
 		md5_finish_ascii( &md5, time );
 		oauth_params_add( &p_out, "sig", time );
 		
-		fmt = oauth_params_string( p_out );
+		reply = oauth_params_string( p_out );
 		oauth_params_free( &p_out );
 		oauth_params_free( &p_in );
-		s = tobase64( fmt );
-		g_free( fmt );
 	}
 	else if( !( s = sasl_get_part( dec, "rspauth" ) ) )
@@ -346,21 +351,18 @@
 		
 		/* Now build the SASL response string: */
-		g_free( dec );
-		dec = g_strdup_printf( "username=\"%s\",realm=\"%s\",nonce=\"%s\",cnonce=\"%s\","
-		                       "nc=%08x,qop=auth,digest-uri=\"%s\",response=%s,charset=%s",
-		                       jd->username, realm, nonce, cnonce, 1, digest_uri, Hh, "utf-8" );
-		s = tobase64( dec );
+		reply = g_strdup_printf( "username=\"%s\",realm=\"%s\",nonce=\"%s\",cnonce=\"%s\","
+		                         "nc=%08x,qop=auth,digest-uri=\"%s\",response=%s,charset=%s",
+		                         jd->username, realm, nonce, cnonce, 1, digest_uri, Hh, "utf-8" );
 	}
 	else
 	{
 		/* We found rspauth, but don't really care... */
-		g_free( s );
-		s = NULL;
-	}
-	
-	reply = xt_new_node( "response", s, NULL );
-	xt_add_attr( reply, "xmlns", XMLNS_SASL );
-	
-	if( !jabber_write_packet( ic, reply ) )
+	}
+	
+	s = reply ? tobase64( reply ) : NULL;
+	reply_pkt = xt_new_node( "response", s, NULL );
+	xt_add_attr( reply_pkt, "xmlns", XMLNS_SASL );
+	
+	if( !jabber_write_packet( ic, reply_pkt ) )
 		goto silent_error;
 	
@@ -376,8 +378,9 @@
 	g_free( cnonce );
 	g_free( nonce );
+	g_free( reply );
 	g_free( realm );
 	g_free( dec );
 	g_free( s );
-	xt_free_node( reply );
+	xt_free_node( reply_pkt );
 	
 	return ret;
