changeset 24860:5d693af3e9e2

Fix a leak "KuSh" discovered using "cppcheck". Fixes #7858. Also, make the relevant code less of a horrible abomination.
author Daniel Atallah <daniel.atallah@gmail.com>
date Mon, 22 Dec 2008 16:41:53 +0000
parents f27910934e69
children e17e325732d0
files libpurple/protocols/gg/buddylist.c
diffstat 1 files changed, 8 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/libpurple/protocols/gg/buddylist.c	Mon Dec 22 16:22:08 2008 +0000
+++ b/libpurple/protocols/gg/buddylist.c	Mon Dec 22 16:41:53 2008 +0000
@@ -216,13 +216,14 @@
 	PurpleBlistNode *gnode, *cnode, *bnode;
 	PurpleGroup *group;
 	PurpleBuddy *buddy;
-
-	char *buddylist = g_strdup("");
+	GString *buddylist;
 	char *ptr;
 
 	if ((blist = purple_get_blist()) == NULL)
 		return NULL;
 
+	buddylist = g_string_sized_new(1024);
+
 	for (gnode = blist->root; gnode != NULL; gnode = gnode->next) {
 		if (!PURPLE_BLIST_NODE_IS_GROUP(gnode))
 			continue;
@@ -247,19 +248,16 @@
 				alias = buddy->alias ? buddy->alias : buddy->name;
 				gname = group->name;
 
-				ptr = buddylist;
-				buddylist = g_strdup_printf(
-						"%s%s;%s;%s;%s;%s;%s;%s;%s%s\r\n",
-						ptr, alias, alias, alias, alias,
+				g_string_append_printf(buddylist,
+						"%s;%s;%s;%s;%s;%s;%s;%s%s\r\n",
+						alias, alias, alias, alias,
 						"", gname, name, "", "");
-
-				g_free(ptr);
 			}
 		}
 	}
 
-	ptr = charset_convert(buddylist, "UTF-8", "CP1250");
-	g_free(buddylist);
+	ptr = charset_convert(buddylist->str, "UTF-8", "CP1250");
+	g_string_free(buddylist, TRUE);
 	return ptr;
 }
 /* }}} */