changeset 23699:fc8047e1fa39

fixed some leaks and made theme loading safer
author Justin Rodriguez <ffdragon@soc.pidgin.im>
date Fri, 08 Aug 2008 21:26:12 +0000
parents f76e9db37141
children 2d436084d866
files libpurple/sound-loader.c libpurple/theme.c pidgin/gtkblist.c
diffstat 3 files changed, 44 insertions(+), 21 deletions(-) [+]
line wrap: on
line diff
--- a/libpurple/sound-loader.c	Fri Aug 08 20:56:44 2008 +0000
+++ b/libpurple/sound-loader.c	Fri Aug 08 21:26:12 2008 +0000
@@ -39,7 +39,7 @@
 	xmlnode *root_node, *sub_node;
 	gchar *filename, *filename_full, *data;
 	GDir *gdir;
-	PurpleSoundTheme *theme;
+	PurpleSoundTheme *theme = NULL;
 
 	/* Find the theme file */
 	gdir = g_dir_open(dir, 0, NULL);
@@ -60,21 +60,23 @@
 	sub_node = xmlnode_get_child(root_node, "description");
 	data = xmlnode_get_data(sub_node);
 
-	theme = g_object_new(PURPLE_TYPE_SOUND_THEME,
-			    "type", "sound",
-			    "name", xmlnode_get_attrib(root_node, "name"),
-			    "author", xmlnode_get_attrib(root_node, "author"),
-			    "image", xmlnode_get_attrib(root_node, "image"),
-			    "directory", dir,
-			    "description", data, NULL);
+	if (xmlnode_get_attrib(root_node, "name") != NULL) {
+		theme = g_object_new(PURPLE_TYPE_SOUND_THEME,
+				    "type", "sound",
+				    "name", xmlnode_get_attrib(root_node, "name"),
+				    "author", xmlnode_get_attrib(root_node, "author"),
+				    "image", xmlnode_get_attrib(root_node, "image"),
+				    "directory", dir,
+				    "description", data, NULL);
 	
-	xmlnode_free(sub_node);
+		xmlnode_free(sub_node);
 
-	while ((sub_node = xmlnode_get_child(root_node, "event")) != NULL){
-		purple_sound_theme_set_file(theme,
-					    xmlnode_get_attrib(sub_node, "name"),
-					    xmlnode_get_attrib(sub_node, "file"));
-		xmlnode_free(sub_node);
+		while ((sub_node = xmlnode_get_child(root_node, "event")) != NULL){
+			purple_sound_theme_set_file(theme,
+						    xmlnode_get_attrib(sub_node, "name"),
+						    xmlnode_get_attrib(sub_node, "file"));
+			xmlnode_free(sub_node);
+		}
 	}
 
 	xmlnode_free(root_node);	
--- a/libpurple/theme.c	Fri Aug 08 20:56:44 2008 +0000
+++ b/libpurple/theme.c	Fri Aug 08 21:26:12 2008 +0000
@@ -22,6 +22,9 @@
  */
 
 #include "theme.h"
+#include "util.h"
+
+#include <string.h>
 
 #define PURPLE_THEME_GET_PRIVATE(PurpleTheme) \
 	((PurpleThemePrivate *) ((PurpleTheme)->priv))
@@ -230,9 +233,21 @@
   return type;
 }
 
+/******************************************************************************
+ * Helper Functions
+ *****************************************************************************/
+
+static gchar*
+theme_clean_text(const gchar *text)
+{
+	gchar *clean_text = g_markup_escape_text(text, strlen(text));	
+	g_strdelimit(clean_text, "\n", ' ');
+	purple_str_strip_char(clean_text, '\r');
+	return clean_text;
+}
 
 /*****************************************************************************
- * Public API functions                                                      *
+ * Public API functions                                                      
  *****************************************************************************/
 
 const gchar *
@@ -256,7 +271,7 @@
 	priv = PURPLE_THEME_GET_PRIVATE(theme);
 
 	g_free(priv->name);
-	priv->name = g_strdup(name);
+	priv->name = theme_clean_text(name);
 }
 
 const gchar *
@@ -280,7 +295,7 @@
 	priv = PURPLE_THEME_GET_PRIVATE(theme);
 
 	g_free(priv->description);
-	priv->description = g_strdup(description);
+	priv->description = theme_clean_text(description);
 }
 
 const gchar *
@@ -304,7 +319,7 @@
 	priv = PURPLE_THEME_GET_PRIVATE(theme);
 
 	g_free(priv->author);
-	priv->author = g_strdup(author);
+	priv->author = theme_clean_text(author);
 }
 
 const gchar *
--- a/pidgin/gtkblist.c	Fri Aug 08 20:56:44 2008 +0000
+++ b/pidgin/gtkblist.c	Fri Aug 08 21:26:12 2008 +0000
@@ -3788,14 +3788,14 @@
 gchar *
 pidgin_blist_get_name_markup(PurpleBuddy *b, gboolean selected, gboolean aliased)
 {
-	const char *name;
-	char *text = NULL, *name_color, *name_font, *status_color, *status_font;
+	const char *name, *name_color, *name_font, *status_color, *status_font;
+	char *text = NULL;
 	PurplePlugin *prpl;
 	PurplePluginProtocolInfo *prpl_info = NULL;
 	PurpleContact *contact;
 	PurplePresence *presence;
 	struct _pidgin_blist_node *gtkcontactnode = NULL;
-	char *idletime = NULL, *statustext = NULL, *nametext;
+	char *idletime = NULL, *statustext = NULL, *nametext = NULL;
 	PurpleConversation *conv = find_conversation_with_buddy(b);
 	gboolean hidden_conv = FALSE;
 	gboolean biglist = purple_prefs_get_bool(PIDGIN_PREFS_ROOT "/blist/show_buddy_icons");
@@ -3971,6 +3971,12 @@
 
 	} else text = g_strdup_printf("<span font_desc='%s' color='%s'>%s</span>", name_font, name_color, nametext); 
 
+	g_free(nametext);
+	if (statustext)
+		g_free(statustext);
+	if (idletime)
+		g_free(idletime);
+
 	if (hidden_conv) {
 		char *tmp = text;
 		text = g_strdup_printf("<b>%s</b>", tmp);