Index: bitlbee.h
===================================================================
--- bitlbee.h	(revision 70e68cfcf2e60a22f4a624446fe346dc254935a1)
+++ bitlbee.h	(revision 5014380af58a2fa51b3ef5afa49d7751eaf6cea1)
@@ -93,6 +93,4 @@
 #undef g_source_remove
 #define g_source_remove         __PLEASE_USE_B_EVENT_REMOVE__
-#undef g_source_remove_by_user_data
-#define g_source_remove_by_user_data    __PLEASE_USE_B_SOURCE_REMOVE_BY_USER_DATA__
 #undef g_main_run
 #define g_main_run              __PLEASE_USE_B_MAIN_RUN__
Index: irc_im.c
===================================================================
--- irc_im.c	(revision 70e68cfcf2e60a22f4a624446fe346dc254935a1)
+++ irc_im.c	(revision 5014380af58a2fa51b3ef5afa49d7751eaf6cea1)
@@ -50,5 +50,5 @@
 
 	memset(nick, 0, MAX_NICK_LENGTH + 1);
-	strcpy(nick, nick_get(bu));
+	strncpy(nick, nick_get(bu), MAX_NICK_LENGTH);
 
 	bu->ui_data = iu = irc_user_new(irc, nick);
@@ -723,4 +723,6 @@
 			g_free(channel);
 			channel = s;
+		} else {
+			g_free(s);
 		}
 	}
Index: irc_send.c
===================================================================
--- irc_send.c	(revision 70e68cfcf2e60a22f4a624446fe346dc254935a1)
+++ irc_send.c	(revision 5014380af58a2fa51b3ef5afa49d7751eaf6cea1)
@@ -175,9 +175,8 @@
 
 	if (iu == irc->user) {
-		irc_write(irc, ":%s MODE %s +%s", irc->root->host, ic->name, ic->mode);
-		irc_send_names(ic);
 		if (ic->topic && *ic->topic) {
 			irc_send_topic(ic, FALSE);
 		}
+		irc_send_names(ic);
 	}
 }
Index: lib/events_glib.c
===================================================================
--- lib/events_glib.c	(revision 70e68cfcf2e60a22f4a624446fe346dc254935a1)
+++ lib/events_glib.c	(revision 5014380af58a2fa51b3ef5afa49d7751eaf6cea1)
@@ -82,5 +82,5 @@
 	}
 
-	event_debug("gaim_io_invoke( %d, %d, 0x%x )\n", g_io_channel_unix_get_fd(source), condition, data);
+	event_debug("gaim_io_invoke( %d, %d, %p )\n", g_io_channel_unix_get_fd(source), condition, data);
 
 	st = closure->function(closure->data, g_io_channel_unix_get_fd(source), gaim_cond);
@@ -101,5 +101,5 @@
 static void gaim_io_destroy(gpointer data)
 {
-	event_debug("gaim_io_destroy( 0x%x )\n", data);
+	event_debug("gaim_io_destroy( 0%p )\n", data);
 	g_free(data);
 }
@@ -127,5 +127,5 @@
 	                         gaim_io_invoke, closure, gaim_io_destroy);
 
-	event_debug("b_input_add( %d, %d, 0x%x, 0x%x ) = %d (%p)\n", source, condition, function, data, st, closure);
+	event_debug("b_input_add( %d, %d, %p, %p ) = %d (%p)\n", source, condition, function, data, st, closure);
 
 	g_io_channel_unref(channel);
@@ -140,5 +140,5 @@
 	gint st = g_timeout_add(timeout, (GSourceFunc) func, data);
 
-	event_debug("b_timeout_add( %d, %d, %d ) = %d\n", timeout, func, data, st);
+	event_debug("b_timeout_add( %d, %p, %p ) = %d\n", timeout, func, data, st);
 
 	return st;
Index: lib/oauth2.c
===================================================================
--- lib/oauth2.c	(revision 70e68cfcf2e60a22f4a624446fe346dc254935a1)
+++ lib/oauth2.c	(revision 5014380af58a2fa51b3ef5afa49d7751eaf6cea1)
@@ -140,7 +140,13 @@
 	struct oauth2_access_token_data *cb_data = req->data;
 	char *atoken = NULL, *rtoken = NULL, *error = NULL;
-	char *content_type;
+	char *content_type = NULL;
 
-	if (getenv("BITLBEE_DEBUG") && req->reply_body) {
+	if (req->status_code <= 0 && !req->reply_body) {
+		cb_data->func(cb_data->data, NULL, NULL, req->status_string);
+		g_free(cb_data);
+		return;
+	}
+
+	if (getenv("BITLBEE_DEBUG")) {
 		printf("%s\n", req->reply_body);
 	}
Index: protocols/jabber/jabber.c
===================================================================
--- protocols/jabber/jabber.c	(revision 70e68cfcf2e60a22f4a624446fe346dc254935a1)
+++ protocols/jabber/jabber.c	(revision 5014380af58a2fa51b3ef5afa49d7751eaf6cea1)
@@ -428,5 +428,5 @@
 	}
 
-	jabber_get_vcard(ic, bud ? bud->full_jid : who);
+	jabber_get_vcard(ic, who);
 }
 
Index: protocols/msn/gw.c
===================================================================
--- protocols/msn/gw.c	(revision 70e68cfcf2e60a22f4a624446fe346dc254935a1)
+++ protocols/msn/gw.c	(revision 5014380af58a2fa51b3ef5afa49d7751eaf6cea1)
@@ -87,12 +87,12 @@
 	gw->polling = FALSE;
 
+	if (req->status_code != 200 || !req->reply_body) {
+		gw->callback(gw->md, -1, B_EV_IO_READ);
+		return;
+	}
+
 	if (getenv("BITLBEE_DEBUG")) {
 		fprintf(stderr, "\n\x1b[90mHTTP:%s\n", req->reply_body);
 		fprintf(stderr, "\n\x1b[97m\n");
-	}
-
-	if (req->status_code != 200) {
-		gw->callback(gw->md, -1, B_EV_IO_READ);
-		return;
 	}
 
@@ -113,5 +113,8 @@
 	if (req->body_size) {
 		g_byte_array_append(gw->in, (const guint8 *) req->reply_body, req->body_size);
-		gw->callback(gw->md, -1, B_EV_IO_READ);
+
+		if (!gw->callback(gw->md, -1, B_EV_IO_READ)) {
+			return;
+		}
 	}
 
Index: protocols/msn/ns.c
===================================================================
--- protocols/msn/ns.c	(revision 70e68cfcf2e60a22f4a624446fe346dc254935a1)
+++ protocols/msn/ns.c	(revision 5014380af58a2fa51b3ef5afa49d7751eaf6cea1)
@@ -181,4 +181,5 @@
 		imcb_error(ic, "Error while reading from server");
 		imc_logout(ic, TRUE);
+		g_free(bytes);
 		return FALSE;
 	}
@@ -188,9 +189,5 @@
 	g_free(bytes);
 
-	/* Ignore ret == 0, it's already disconnected then. */
-	msn_handler(md);
-
-	return TRUE;
-	
+	return msn_handler(md);
 }
 
Index: protocols/oscar/ssi.c
===================================================================
--- protocols/oscar/ssi.c	(revision 70e68cfcf2e60a22f4a624446fe346dc254935a1)
+++ protocols/oscar/ssi.c	(revision 5014380af58a2fa51b3ef5afa49d7751eaf6cea1)
@@ -66,5 +66,5 @@
 				newitem->gid += 0x0001;
 				for (cur = *list, i = 0; ((cur) && (!i)); cur = cur->next) {
-					if ((cur->gid == newitem->gid) && (cur->gid == newitem->gid)) {
+					if ((cur->bid == newitem->bid) && (cur->gid == newitem->gid)) {
 						i = 1;
 					}
Index: protocols/twitter/twitter.c
===================================================================
--- protocols/twitter/twitter.c	(revision 70e68cfcf2e60a22f4a624446fe346dc254935a1)
+++ protocols/twitter/twitter.c	(revision 5014380af58a2fa51b3ef5afa49d7751eaf6cea1)
@@ -483,8 +483,6 @@
 }
 
-static gboolean twitter_length_check(struct im_connection *ic, gchar * msg)
-{
-	int max = set_getint(&ic->acc->set, "message_length"), len;
-	int target_len = set_getint(&ic->acc->set, "target_url_length");
+int twitter_message_len(gchar *msg, int target_len)
+{
 	int url_len_diff = 0;
 
@@ -493,5 +491,14 @@
 	}
 
-	if (max == 0 || (len = g_utf8_strlen(msg, -1) + url_len_diff) <= max) {
+	return g_utf8_strlen(msg, -1) + url_len_diff;
+}
+
+static gboolean twitter_length_check(struct im_connection *ic, gchar * msg)
+{
+	int max = set_getint(&ic->acc->set, "message_length");
+	int target_len = set_getint(&ic->acc->set, "target_url_length");
+	int len = twitter_message_len(msg, target_len);
+
+	if (max == 0 || len <= max) {
 		return TRUE;
 	}
Index: protocols/yahoo/yahoo2.h
===================================================================
--- protocols/yahoo/yahoo2.h	(revision 70e68cfcf2e60a22f4a624446fe346dc254935a1)
+++ protocols/yahoo/yahoo2.h	(revision 5014380af58a2fa51b3ef5afa49d7751eaf6cea1)
@@ -33,6 +33,4 @@
 #undef malloc
 #define malloc(x)             g_malloc(x)
-#undef calloc
-#define calloc(x, y)          g_calloc(x, y)
 #undef realloc
 #define realloc(x, y)         g_realloc(x, y)
Index: unix.c
===================================================================
--- unix.c	(revision 70e68cfcf2e60a22f4a624446fe346dc254935a1)
+++ unix.c	(revision 5014380af58a2fa51b3ef5afa49d7751eaf6cea1)
@@ -212,13 +212,23 @@
 		       argv[0], argv[0], argv[0], argv[0], argv[0]);
 	} else if (strcmp(argv[2], "enc") == 0) {
-		pass_len = arc_encode(argv[4], strlen(argv[4]), (unsigned char **) &pass_cr, argv[3], 12);
-		printf("%s\n", base64_encode(pass_cr, pass_len));
+		char *encoded;
+
+		pass_len = arc_encode(argv[4], strlen(argv[4]), &pass_cr, argv[3], 12);
+
+		encoded = base64_encode(pass_cr, pass_len);
+		printf("%s\n", encoded);
+		g_free(encoded);
+		g_free(pass_cr);
 	} else if (strcmp(argv[2], "dec") == 0) {
-		pass_len = base64_decode(argv[4], (unsigned char **) &pass_cr);
+		pass_len = base64_decode(argv[4], &pass_cr);
 		arc_decode(pass_cr, pass_len, (char **) &pass_cl, argv[3]);
 		printf("%s\n", pass_cl);
+
+		g_free(pass_cr);
+		g_free(pass_cl);
 	} else if (strcmp(argv[2], "hash") == 0) {
 		md5_byte_t pass_md5[21];
 		md5_state_t md5_state;
+		char *encoded;
 
 		random_bytes(pass_md5 + 16, 5);
@@ -228,5 +238,7 @@
 		md5_finish(&md5_state, pass_md5);
 
-		printf("%s\n", base64_encode(pass_md5, 21));
+		encoded = base64_encode(pass_md5, 21);
+		printf("%s\n", encoded);
+		g_free(encoded);
 	} else if (strcmp(argv[2], "unhash") == 0) {
 		printf("Hash %s submitted to a massive Beowulf cluster of\n"
