[goffice] Memory: fix confusion between g_malloc and libxml allocations.
- From: Morten Welinder <mortenw src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [goffice] Memory: fix confusion between g_malloc and libxml allocations.
- Date: Tue, 24 Aug 2010 16:43:22 +0000 (UTC)
commit a23d65980625de312f25d26ba0f993bdb09cfcef
Author: Morten Welinder <terra gnome org>
Date: Tue Aug 24 12:42:47 2010 -0400
Memory: fix confusion between g_malloc and libxml allocations.
ChangeLog | 7 ++
NEWS | 1 +
goffice/app/go-plugin-service.c | 99 ++++++++++++++++--------------
goffice/app/go-plugin.c | 53 +++++++++-------
goffice/component/go-component-factory.c | 21 +++++--
5 files changed, 105 insertions(+), 76 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 77b4ae9..f7b254c 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2010-08-24 Morten Welinder <terra gnome org>
+
+ * goffice/component/go-component-factory.c: Fix char-xmlChar
+ confusion.
+ * goffice/app/go-plugin-service.c: Ditto.
+ * goffice/app/go-plugin.c: Ditto.
+
2010-08-24 Jean Brefort <jean brefort normalesup org>
* goffice/app/go-plugin-service.c (go_plugin_service_finalize),
diff --git a/NEWS b/NEWS
index bb9f9e7..68ad593 100644
--- a/NEWS
+++ b/NEWS
@@ -11,6 +11,7 @@ Morten:
* Limit formats to sane number of decimals. [#627066]
* Fix minor go_string_replace issue.
* Plug leaks.
+ * Fix char-xmlChar confusion.
--------------------------------------------------------------------------
goffice 0.8.9:
diff --git a/goffice/app/go-plugin-service.c b/goffice/app/go-plugin-service.c
index 6270bac..80a9569 100644
--- a/goffice/app/go-plugin-service.c
+++ b/goffice/app/go-plugin-service.c
@@ -28,6 +28,15 @@
#include <string.h>
#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;
+}
static GHashTable *services = NULL;
@@ -67,7 +76,7 @@ go_plugin_service_finalize (GObject *obj)
GOPluginService *service = GO_PLUGIN_SERVICE (obj);
GObjectClass *parent_class;
- xmlFree (service->id);
+ g_free (service->id);
service->id = NULL;
g_free (service->saved_description);
service->saved_description = NULL;
@@ -271,42 +280,48 @@ go_plugin_service_file_opener_read_xml (GOPluginService *service, xmlNode *tree,
information_node = go_xml_get_child_by_name (tree, "information");
if (information_node != NULL) {
- xmlNode *node;
- xmlChar *val;
-
- node = go_xml_get_child_by_name_by_lang (
- information_node, "description");
- if (node != NULL) {
- val = xmlNodeGetContent (node);
- description = g_strdup ((gchar *)val);
- xmlFree (val);
- } else {
- description = NULL;
- }
+ xmlNode *node = go_xml_get_child_by_name_by_lang
+ (information_node, "description");
+ description = node ? xml2c (xmlNodeGetContent (node)) : NULL;
} else {
description = NULL;
}
if (description != NULL) {
GSList *suffixes = NULL, *mimes = NULL;
- char *tmp;
xmlNode *list, *node;
GOPluginServiceFileOpener *service_file_opener = GO_PLUGIN_SERVICE_FILE_OPENER (service);
list = go_xml_get_child_by_name (tree, "suffixes");
if (list != NULL) {
- for (node = list->xmlChildrenNode; node != NULL; node = node->next)
- if (strcmp (node->name, "suffix") == 0 &&
- (tmp = xmlNodeGetContent (node)) != NULL)
- GO_SLIST_PREPEND (suffixes, tmp);
+ for (node = list->xmlChildrenNode; node != NULL; node = node->next) {
+ char *tmp;
+
+ if (strcmp (node->name, "suffix"))
+ continue;
+
+ tmp = xml2c (xmlNodeGetContent (node));
+ if (!tmp)
+ continue;
+
+ GO_SLIST_PREPEND (suffixes, tmp);
+ }
}
GO_SLIST_REVERSE (suffixes);
list = go_xml_get_child_by_name (tree, "mime-types");
if (list != NULL) {
- for (node = list->xmlChildrenNode; node != NULL; node = node->next)
- if (strcmp (node->name, "mime-type") == 0 &&
- (tmp = xmlNodeGetContent (node)) != NULL)
- GO_SLIST_PREPEND (mimes, tmp);
+ for (node = list->xmlChildrenNode; node != NULL; node = node->next) {
+ char *tmp;
+
+ if (strcmp (node->name, "mime-type"))
+ continue;
+
+ tmp = xml2c (xmlNodeGetContent (node));
+ if (!tmp)
+ continue;
+
+ GO_SLIST_PREPEND (mimes, tmp);
+ }
}
GO_SLIST_REVERSE (mimes);
@@ -592,48 +607,38 @@ go_plugin_service_file_saver_read_xml (GOPluginService *service, xmlNode *tree,
GO_INIT_RET_ERROR_INFO (ret_error);
information_node = go_xml_get_child_by_name (tree, "information");
if (information_node != NULL) {
- xmlNode *node;
- xmlChar *val;
-
- node = go_xml_get_child_by_name_by_lang (
- information_node, "description");
- if (node != NULL) {
- val = xmlNodeGetContent (node);
- description = g_strdup ((gchar *)val);
- xmlFree (val);
- } else {
- description = NULL;
- }
+ xmlNode *node = go_xml_get_child_by_name_by_lang
+ (information_node, "description");
+ description = node ? xml2c (xmlNodeGetContent (node)) : NULL;
} else {
description = NULL;
}
if (description != NULL) {
- xmlChar *s;
int scope = GO_FILE_SAVE_WORKBOOK;
int level = GO_FILE_FL_WRITE_ONLY;
GOPluginServiceFileSaver *psfs =
GO_PLUGIN_SERVICE_FILE_SAVER (service);
- s = go_xml_node_get_cstr (tree, "file_extension");
- psfs->file_extension = g_strdup (CXML2C (s));
- xmlFree (s);
+ psfs->file_extension =
+ xml2c (go_xml_node_get_cstr (tree, "file_extension"));
- s = go_xml_node_get_cstr (tree, "mime_type");
- psfs->mime_type = g_strdup (CXML2C (s));
- xmlFree (s);
+ psfs->mime_type =
+ xml2c (go_xml_node_get_cstr (tree, "mime_type"));
psfs->description = description;
- (void)go_xml_node_get_enum (tree, "format_level",
- GO_TYPE_FILE_FORMAT_LEVEL, &level);
+ (void)go_xml_node_get_enum
+ (tree, "format_level",
+ GO_TYPE_FILE_FORMAT_LEVEL, &level);
psfs->format_level = (GOFileFormatLevel)level;
if (!go_xml_node_get_int (tree, "default_saver_priority", &(psfs->default_saver_priority)))
psfs->default_saver_priority = -1;
- (void)go_xml_node_get_enum (tree, "save_scope",
- GO_TYPE_FILE_SAVE_SCOPE, &scope);
+ (void)go_xml_node_get_enum
+ (tree, "save_scope",
+ GO_TYPE_FILE_SAVE_SCOPE, &scope);
psfs->save_scope = (GOFileSaveScope)scope;
if (!go_xml_node_get_bool (tree, "overwrite_files", &(psfs->overwrite_files)))
@@ -1008,14 +1013,14 @@ go_plugin_service_new (GOPlugin *plugin, xmlNode *tree, GOErrorInfo **ret_error)
ctor = g_hash_table_lookup (services, type_str);
if (ctor == NULL) {
*ret_error = go_error_info_new_printf (_("Unknown service type: %s."), type_str);
- g_free (type_str);
+ xmlFree (type_str);
return NULL;
}
xmlFree (type_str);
service = g_object_new (ctor(), NULL);
service->plugin = plugin;
- service->id = go_xml_node_get_cstr (tree, "id");
+ service->id = xml2c (go_xml_node_get_cstr (tree, "id"));
if (service->id == NULL)
service->id = xmlStrdup ("default");
diff --git a/goffice/app/go-plugin.c b/goffice/app/go-plugin.c
index 5a72f2e..4d96db1 100644
--- a/goffice/app/go-plugin.c
+++ b/goffice/app/go-plugin.c
@@ -61,6 +61,18 @@ static void plugin_get_loader_if_needed (GOPlugin *plugin, GOErrorInfo **ret_err
static void go_plugin_read (GOPlugin *plugin, gchar const *dir_name, GOErrorInfo **ret_error);
static void go_plugin_load_base (GOPlugin *plugin, GOErrorInfo **ret_error);
+#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;
+}
+
+
/*
* GOPlugin
*/
@@ -615,7 +627,7 @@ go_plugin_read_dependency_list (xmlNode *tree)
if (strcmp (node->name, "dep_plugin") == 0) {
gchar *plugin_id;
- plugin_id = xmlGetProp (node, (xmlChar *)"id");
+ plugin_id = xml2c (xmlGetProp (node, CC2XML ("id")));
if (plugin_id != NULL) {
PluginDependency *dep;
@@ -643,7 +655,7 @@ go_plugin_read_service_list (GOPlugin *plugin, xmlNode *tree, GOErrorInfo **ret_
g_return_val_if_fail (tree != NULL, NULL);
GO_INIT_RET_ERROR_INFO (ret_error);
- node = go_xml_get_child_by_name (tree, (xmlChar *)"services");
+ node = go_xml_get_child_by_name (tree, CC2XML ("services"));
if (node == NULL)
return NULL;
node = node->xmlChildrenNode;
@@ -692,10 +704,10 @@ go_plugin_read_loader_attrs (xmlNode *tree)
if (strcmp (node->name, "attribute") == 0) {
gchar *name, *value;
- name = xmlGetProp (node, (xmlChar *)"name");
+ name = xml2c (xmlGetProp (node, CC2XML ("name")));
if (name != NULL) {
if (g_hash_table_lookup (hash, name) == NULL) {
- value = xmlGetProp (node, (xmlChar *)"value");
+ value = xml2c (xmlGetProp (node, CC2XML ("value")));
g_hash_table_insert (hash, name, value);
} else {
g_warning ("Duplicated \"%s\" attribute in plugin.xml file.", name);
@@ -755,47 +767,40 @@ go_plugin_read (GOPlugin *plugin, gchar const *dir_name, GOErrorInfo **ret_error
return;
}
tree = doc->xmlRootNode;
- id = xmlGetProp (tree, (xmlChar *)"id");
- information_node = go_xml_get_child_by_name (tree, (xmlChar *)"information");
+ id = xml2c (xmlGetProp (tree, CC2XML ("id")));
+
+ information_node = go_xml_get_child_by_name (tree, CC2XML ("information"));
if (information_node != NULL) {
xmlNode *node;
- xmlChar *val;
node = go_xml_get_child_by_name_by_lang (information_node, "name");
- if (node != NULL) {
- val = xmlNodeGetContent (node);
- name = g_strdup ((gchar *)val);
- xmlFree (val);
- } else
- name = NULL;
+ name = node ? xml2c (xmlNodeGetContent (node)) : NULL;
node = go_xml_get_child_by_name_by_lang (information_node, "description");
- if (node != NULL) {
- val = xmlNodeGetContent (node);
- description = g_strdup ((gchar *)val);
- xmlFree (val);
- } else
- description = NULL;
- if (go_xml_get_child_by_name (information_node, (xmlChar const *)"require_explicit_enabling"))
+ description = node ? xml2c (xmlNodeGetContent (node)) : NULL;
+
+ if (go_xml_get_child_by_name (information_node, CC2XML ("require_explicit_enabling")))
require_explicit_enabling = TRUE;
- if (go_xml_get_child_by_name (information_node, (xmlChar const *)"autoload"))
+ if (go_xml_get_child_by_name (information_node, CC2XML ("autoload")))
autoload = TRUE;
} else {
name = NULL;
description = NULL;
}
- dependencies_node = go_xml_get_child_by_name (tree, (xmlChar *)"dependencies");
+
+ dependencies_node = go_xml_get_child_by_name (tree, CC2XML ("dependencies"));
if (dependencies_node != NULL) {
dependency_list = go_plugin_read_dependency_list (dependencies_node);
} else {
dependency_list = NULL;
}
- loader_node = go_xml_get_child_by_name (tree, (xmlChar *)"loader");
+
+ loader_node = go_xml_get_child_by_name (tree, CC2XML ("loader"));
if (loader_node != NULL) {
char *p;
- loader_id = xmlGetProp (loader_node, (xmlChar *)"type");
+ loader_id = xml2c (xmlGetProp (loader_node, CC2XML ("type")));
if (loader_id != NULL && (p = strchr (loader_id, ':')) != NULL) {
loader_attrs = go_plugin_read_loader_attrs (loader_node);
if (strcmp (loader_id, BUILTIN_LOADER_MODULE_ID) != 0) {
diff --git a/goffice/component/go-component-factory.c b/goffice/component/go-component-factory.c
index 9d2d03b..469f6ad 100644
--- a/goffice/component/go-component-factory.c
+++ b/goffice/component/go-component-factory.c
@@ -34,6 +34,17 @@
static GSList *refd_plugins = NULL;
+#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;
+}
+
/***************************************************************************/
/* Support component engines in plugins */
@@ -123,9 +134,9 @@ go_component_type_service_read_xml (GOPluginService * service, xmlNode * tree,
go_mime_type_free);
for (ptr = tree->xmlChildrenNode; ptr != NULL; ptr = ptr->next)
if (0 == xmlStrcmp (ptr->name, "mime_type")) {
- char *name = xmlGetProp (ptr, "name");
- char *priority = xmlGetProp (ptr, "priority");
- char *support_clipboard = xmlGetProp (ptr, "clipboard");
+ char *name = xml2c (xmlGetProp (ptr, "name"));
+ xmlChar *priority = xmlGetProp (ptr, "priority");
+ xmlChar *support_clipboard = xmlGetProp (ptr, "clipboard");
GOMimeType *mime_type =
g_hash_table_lookup (mime_types, name);
int i;
@@ -157,9 +168,9 @@ go_component_type_service_read_xml (GOPluginService * service, xmlNode * tree,
mime_type->component_type_name = g_strdup (service->id);
mime_type->priority = i;
comp_service->mime_types = g_slist_append (comp_service->mime_types, g_strdup (name));
- xmlFree (name);
+ g_free (name);
} else
- xmlFree (name);
+ g_free (name);
if (support_clipboard)
xmlFree (support_clipboard);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]