Index: bitlbee.c
===================================================================
--- bitlbee.c	(revision b9d1fdc7208e7329122e76e1aa67384442c1cfae)
+++ bitlbee.c	(revision 7de07a0165bbe2823fadcc008575ba7eaf69a285)
@@ -236,12 +236,12 @@
 	irc_t *irc = data;
 	int st, size;
-	char *temp;
-
-	if (irc->sendbuffer == NULL) {
-		return FALSE;
-	}
-
-	size = strlen(irc->sendbuffer);
-	st = write(irc->fd, irc->sendbuffer, size);
+
+	size = irc->sendbuffer->len;
+
+	if (size == 0) {
+		return FALSE;
+	}
+
+	st = write(irc->fd, irc->sendbuffer->str, size);
 
 	if (st == 0 || (st < 0 && !sockerr_again())) {
@@ -253,13 +253,10 @@
 
 	if (st == size) {
-		g_free(irc->sendbuffer);
-		irc->sendbuffer = NULL;
+		g_string_truncate(irc->sendbuffer, 0);
 		irc->w_watch_source_id = 0;
 
 		return FALSE;
 	} else {
-		temp = g_strdup(irc->sendbuffer + st);
-		g_free(irc->sendbuffer);
-		irc->sendbuffer = temp;
+		g_string_erase(irc->sendbuffer, 0, st);
 
 		return TRUE;
Index: irc.c
===================================================================
--- irc.c	(revision b9d1fdc7208e7329122e76e1aa67384442c1cfae)
+++ irc.c	(revision 7de07a0165bbe2823fadcc008575ba7eaf69a285)
@@ -62,4 +62,6 @@
 	irc->iconv = (GIConv) - 1;
 	irc->oconv = (GIConv) - 1;
+
+	irc->sendbuffer = g_string_sized_new(IRC_MAX_LINE * 2);
 
 	if (global.conf->ping_interval > 0 && global.conf->ping_timeout > 0) {
@@ -305,5 +307,5 @@
 	}
 
-	g_free(irc->sendbuffer);
+	g_string_free(irc->sendbuffer, TRUE);
 	g_free(irc->readbuffer);
 	g_free(irc->password);
@@ -595,6 +597,5 @@
 
 		if (now) {
-			g_free(irc->sendbuffer);
-			irc->sendbuffer = g_strdup("\r\n");
+			g_string_assign(irc->sendbuffer, "\r\n");
 		}
 		irc_vawrite(temp->data, format, params);
@@ -611,5 +612,4 @@
 void irc_vawrite(irc_t *irc, char *format, va_list params)
 {
-	int size;
 	char line[IRC_MAX_LINE + 1];
 
@@ -638,14 +638,5 @@
 	g_strlcat(line, "\r\n", IRC_MAX_LINE + 1);
 
-	if (irc->sendbuffer != NULL) {
-		gsize line_len = strlen(line);
-		gsize buffer_len = strlen(irc->sendbuffer);
-
-		size = buffer_len + line_len;
-		irc->sendbuffer = g_renew(char, irc->sendbuffer, size + 1);
-		strcpy((irc->sendbuffer + buffer_len), line);
-	} else {
-		irc->sendbuffer = g_strdup(line);
-	}
+	g_string_append(irc->sendbuffer, line);
 
 	if (irc->w_watch_source_id == 0) {
@@ -669,21 +660,17 @@
 {
 	ssize_t n;
-	size_t len;
-
-	if (irc->sendbuffer == NULL) {
+	size_t len = irc->sendbuffer->len;
+
+	if (len == 0) {
 		return;
 	}
 
-	len = strlen(irc->sendbuffer);
-	if ((n = send(irc->fd, irc->sendbuffer, len, 0)) == len) {
-		g_free(irc->sendbuffer);
-		irc->sendbuffer = NULL;
+	if ((n = send(irc->fd, irc->sendbuffer->str, len, 0)) == len) {
+		g_string_truncate(irc->sendbuffer, 0);
 
 		b_event_remove(irc->w_watch_source_id);
 		irc->w_watch_source_id = 0;
 	} else if (n > 0) {
-		char *s = g_strdup(irc->sendbuffer + n);
-		g_free(irc->sendbuffer);
-		irc->sendbuffer = s;
+		g_string_erase(irc->sendbuffer, 0, n);
 	}
 	/* Otherwise something went wrong and we don't currently care
@@ -702,6 +689,5 @@
 		b_event_remove(irc->w_watch_source_id);
 		irc->w_watch_source_id = 0;
-		g_free(irc->sendbuffer);
-		irc->sendbuffer = NULL;
+		g_string_truncate(irc->sendbuffer, 0);
 	}
 
Index: irc.h
===================================================================
--- irc.h	(revision b9d1fdc7208e7329122e76e1aa67384442c1cfae)
+++ irc.h	(revision 7de07a0165bbe2823fadcc008575ba7eaf69a285)
@@ -85,5 +85,5 @@
 	double last_pong;
 	int pinging;
-	char *sendbuffer;
+	GString *sendbuffer;
 	char *readbuffer;
 	GIConv iconv, oconv;
Index: unix.c
===================================================================
--- unix.c	(revision b9d1fdc7208e7329122e76e1aa67384442c1cfae)
+++ unix.c	(revision 7de07a0165bbe2823fadcc008575ba7eaf69a285)
@@ -373,5 +373,5 @@
 		sock_make_blocking(irc->fd);
 		if (irc->sendbuffer) {
-			(void) write(irc->fd, irc->sendbuffer, strlen(irc->sendbuffer));
+			(void) write(irc->fd, irc->sendbuffer->str, irc->sendbuffer->len);
 		}
 		(void) write(irc->fd, message, sizeof(message) - 1);
