soc.2008.themes: f424012f: fixed some leaks and made theme loading ...

ffdragon at soc.pidgin.im ffdragon at soc.pidgin.im
Fri Aug 8 17:35:39 EDT 2008


-----------------------------------------------------------------
Revision: f424012faa736393548c2892a144c24d19a678fa
Ancestor: e66abb64d93591a45f6729b2b9e64c2f0734ccf8
Author: ffdragon at soc.pidgin.im
Date: 2008-08-08T21:26:12
Branch: im.pidgin.soc.2008.themes
URL: http://d.pidgin.im/viewmtn/revision/info/f424012faa736393548c2892a144c24d19a678fa

Modified files:
        libpurple/sound-loader.c libpurple/theme.c pidgin/gtkblist.c

ChangeLog: 

fixed some leaks and made theme loading safer

-------------- next part --------------
============================================================
--- libpurple/sound-loader.c	6ec2cede63527ed9d17f1a8b4b98bc7fee1e621c
+++ libpurple/sound-loader.c	028d810cf20c1e1877873f0677dca7f5693aacc2
@@ -39,7 +39,7 @@ purple_sound_loader_build(const gchar *d
 	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 @@ purple_sound_loader_build(const gchar *d
 	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);	
============================================================
--- libpurple/theme.c	eb64e15deabc0a0a74912faac985bdde886c3aa4
+++ libpurple/theme.c	53cc43633c204df22cf78a1a9cf18daddb897892
@@ -22,7 +22,10 @@
  */
 
 #include "theme.h"
+#include "util.h"
 
+#include <string.h>
+
 #define PURPLE_THEME_GET_PRIVATE(PurpleTheme) \
 	((PurpleThemePrivate *) ((PurpleTheme)->priv))
 
@@ -230,9 +233,21 @@ purple_theme_get_type (void)
   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 @@ purple_theme_set_name(PurpleTheme *theme
 	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 @@ purple_theme_set_description(PurpleTheme
 	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 @@ purple_theme_set_author(PurpleTheme *the
 	priv = PURPLE_THEME_GET_PRIVATE(theme);
 
 	g_free(priv->author);
-	priv->author = g_strdup(author);
+	priv->author = theme_clean_text(author);
 }
 
 const gchar *
============================================================
--- pidgin/gtkblist.c	5881be3c87374f9ca822390a38d0c94e4c83bc7d
+++ pidgin/gtkblist.c	81db9a9e37000b5bab910cfe789648509d286f35
@@ -3788,14 +3788,14 @@ pidgin_blist_get_name_markup(PurpleBuddy
 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 @@ pidgin_blist_get_name_markup(PurpleBuddy
 
 	} 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);


More information about the Commits mailing list