[gnumeric] Memory: fix confusion between g_malloc and libxml allocations.



commit 76745a2d47f3168920d3d7c4d433c9a662d8b303
Author: Morten Welinder <terra gnome org>
Date:   Tue Aug 24 12:46:16 2010 -0400

    Memory: fix confusion between g_malloc and libxml allocations.

 ChangeLog        |    3 +++
 NEWS             |    1 +
 src/gnm-plugin.c |   47 ++++++++++++++++++++++++++---------------------
 3 files changed, 30 insertions(+), 21 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index ecc61e8..dc4698e 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,8 @@
 2010-08-24  Morten Welinder  <terra gnome org>
 
+	* src/gnm-plugin.c (plugin_service_function_group_read_xml)
+	(plugin_service_ui_read_xml): Fix char-xmlChar confusion.
+
 	* src/libgnumeric.c (gnm_pre_parse_init): Make it possible to turn
 	on glib memory profiler.
 
diff --git a/NEWS b/NEWS
index 8740eef..824ed8d 100644
--- a/NEWS
+++ b/NEWS
@@ -18,6 +18,7 @@ Morten:
 	* Plug odf importer leak.  [#627759]
 	* Extend domain of IMPOWER.  [#627775]
 	* Allow use of glib's memory profiler.
+	* Fix some confusion of char vs. xmlChar.
 
 --------------------------------------------------------------------------
 Gnumeric 1.10.9
diff --git a/src/gnm-plugin.c b/src/gnm-plugin.c
index 9d42ad1..f35837f 100644
--- a/src/gnm-plugin.c
+++ b/src/gnm-plugin.c
@@ -22,6 +22,14 @@
 #define CXML2C(s) ((char const *)(s))
 #define CC2XML(s) ((xmlChar const *)(s))
 
+static char *
+xml2c (xmlChar *src)
+{
+	char *dst = g_strdup (CXML2C (src));
+	xmlFree (src);
+	return dst;
+}
+
 typedef GOPluginServiceSimpleClass	PluginServiceFunctionGroupClass;
 struct _PluginServiceFunctionGroup {
 	GOPluginServiceSimple	base;
@@ -75,35 +83,35 @@ plugin_service_function_group_read_xml (GOPluginService *service, xmlNode *tree,
 	}
 	translated_category_node = go_xml_get_child_by_name_by_lang (tree, "category");
 	if (translated_category_node != NULL) {
-		gchar *lang;
+		xmlChar *lang;
 
 		lang = go_xml_node_get_cstr (translated_category_node, "lang");
 		if (lang != NULL) {
-			xmlChar *val;
-
-			val = xmlNodeGetContent (translated_category_node);
-			translated_category_name = g_strdup (CXML2C (val));
-			xmlFree (val);
-			g_free (lang);
+			translated_category_name =
+				xml2c (xmlNodeGetContent (translated_category_node));
+			xmlFree (lang);
 		} else {
 			translated_category_name = NULL;
 		}
 	} else {
 		translated_category_name = NULL;
 	}
-	functions_node = go_xml_get_child_by_name (tree, (xmlChar *)"functions");
+	functions_node = go_xml_get_child_by_name (tree, CC2XML ("functions"));
 	if (functions_node != NULL) {
 		xmlNode *node;
 
-		textdomain = go_xml_node_get_cstr (functions_node, "textdomain");
+		textdomain = xml2c (go_xml_node_get_cstr (functions_node, "textdomain"));
 
 		for (node = functions_node->xmlChildrenNode; node != NULL; node = node->next) {
 			gchar *func_name;
 
-			if (strcmp (CXML2C (node->name), "function") != 0 ||
-			    (func_name = go_xml_node_get_cstr (node, "name")) == NULL) {
+			if (strcmp (CXML2C (node->name), "function") != 0)
 				continue;
-			}
+
+			func_name = xml2c (go_xml_node_get_cstr (node, "name"));
+			if (!func_name)
+				continue;
+
 			GO_SLIST_PREPEND (function_name_list, func_name);
 		}
 		GO_SLIST_REVERSE (function_name_list);
@@ -330,7 +338,7 @@ plugin_service_ui_read_xml (GOPluginService *service, xmlNode *tree, GOErrorInfo
 	GSList *actions = NULL;
 
 	GO_INIT_RET_ERROR_INFO (ret_error);
-	file_name = go_xml_node_get_cstr (tree, "file");
+	file_name = xml2c (go_xml_node_get_cstr (tree, "file"));
 	if (file_name == NULL) {
 		*ret_error = go_error_info_new_str (
 		             _("Missing file name."));
@@ -352,13 +360,10 @@ plugin_service_ui_read_xml (GOPluginService *service, xmlNode *tree, GOErrorInfo
 //			label = go_xml_node_get_cstr (ptr, "label");
 /*****************************************************************************************/
 			label_node = go_xml_get_child_by_name_no_lang (ptr, "label");
-			if (label_node != NULL) {
-				xmlChar *val = xmlNodeGetContent (label_node);
-				label = g_strdup (CXML2C (val));
-				xmlFree (val);
-			} else {
-				label = NULL;
-			}
+			label = label_node
+				? xml2c (xmlNodeGetContent (label_node))
+				: NULL;
+
 			label_node = go_xml_get_child_by_name_by_lang (ptr, "label");
 			if (label_node != NULL) {
 				gchar *lang;
@@ -382,7 +387,7 @@ plugin_service_ui_read_xml (GOPluginService *service, xmlNode *tree, GOErrorInfo
 				(GnmActionHandler) cb_ui_service_activate);
 			if (NULL != name) xmlFree (name);
 			g_free (label);
-			if (NULL != name) xmlFree (icon);
+			if (NULL != icon) xmlFree (icon);
 			if (NULL != action)
 				GO_SLIST_PREPEND (actions, action);
 		}



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]