diff libpurple/sound-loader.c @ 25119: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 fbf72bbd1084
children b37ccfd1697b
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);