[tracker: 1/2] tt2sgml: Fix memory leaks and memory corruptions
- From: Sam Thursfield <sthursfield src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tracker: 1/2] tt2sgml: Fix memory leaks and memory corruptions
- Date: Tue, 18 Dec 2018 23:27:40 +0000 (UTC)
commit c3318ce164465b1753f3d98a8c851d0b08b2ac98
Author: Andrea Azzarone <andrea azzarone canonical com>
Date: Tue Dec 18 13:47:47 2018 +0000
tt2sgml: Fix memory leaks and memory corruptions
Fixes: https://gitlab.gnome.org/GNOME/tracker/issues/66
docs/tools/ttl2sgml.c | 6 ++++--
docs/tools/ttl_model.c | 27 ++++++++++++++-------------
docs/tools/ttl_sgml.c | 1 +
docs/tools/ttlresource2sgml.c | 10 +++++++---
4 files changed, 26 insertions(+), 18 deletions(-)
---
diff --git a/docs/tools/ttl2sgml.c b/docs/tools/ttl2sgml.c
index 433e44315..7acf53482 100644
--- a/docs/tools/ttl2sgml.c
+++ b/docs/tools/ttl2sgml.c
@@ -107,7 +107,7 @@ main (gint argc, gchar **argv)
Ontology *ontology = NULL;
OntologyDescription *description = NULL;
GList *description_files, *l;
- GFile *ontology_file, *output_file;
+ g_autoptr(GFile) ontology_file = NULL, output_file = NULL;
gchar *path;
/* Translators: this messagge will apper immediately after the */
@@ -150,7 +150,7 @@ main (gint argc, gchar **argv)
for (l = description_files; l; l = l->next) {
Ontology *file_ontology = NULL;
- GFile *ttl_file, *ttl_output_file;
+ g_autoptr(GFile) ttl_file = NULL, ttl_output_file = NULL;
gchar *filename;
description = ttl_loader_load_description (l->data);
@@ -171,9 +171,11 @@ main (gint argc, gchar **argv)
ttl_loader_free_ontology (file_ontology);
ttl_loader_free_description (description);
}
+ g_list_free_full (description_files, (GDestroyNotify) g_object_unref);
generate_ontology_class_docs (ontology, output_file);
+ ttl_loader_free_ontology (ontology);
g_option_context_free (context);
return 0;
diff --git a/docs/tools/ttl_model.c b/docs/tools/ttl_model.c
index 50197a7d3..cf45d5227 100644
--- a/docs/tools/ttl_model.c
+++ b/docs/tools/ttl_model.c
@@ -45,14 +45,14 @@ ttl_model_class_free (OntologyClass *def)
{
g_free (def->classname);
- g_list_foreach (def->superclasses, (GFunc) g_free, NULL);
- g_list_foreach (def->subclasses, (GFunc) g_free, NULL);
- g_list_foreach (def->in_domain_of, (GFunc) g_free, NULL);
- g_list_foreach (def->in_range_of, (GFunc) g_free, NULL);
+ g_list_free_full (def->superclasses, (GDestroyNotify) g_free);
+ g_list_free_full (def->subclasses, (GDestroyNotify) g_free);
+ g_list_free_full (def->in_domain_of, (GDestroyNotify) g_free);
+ g_list_free_full (def->in_range_of, (GDestroyNotify) g_free);
g_free (def->description);
- g_list_foreach (def->instances, (GFunc) g_free, NULL);
+ g_list_free_full (def->instances, (GDestroyNotify) g_free);
g_free (def);
}
@@ -84,11 +84,11 @@ ttl_model_property_free (OntologyProperty *def)
{
g_free (def->propertyname);
- g_list_foreach (def->type, (GFunc) g_free, NULL);
- g_list_foreach (def->domain, (GFunc) g_free, NULL);
- g_list_foreach (def->range, (GFunc) g_free, NULL);
- g_list_foreach (def->superproperties, (GFunc) g_free, NULL);
- g_list_foreach (def->subproperties, (GFunc) g_free, NULL);
+ g_list_free_full (def->type, (GDestroyNotify) g_free);
+ g_list_free_full (def->domain, (GDestroyNotify) g_free);
+ g_list_free_full (def->range, (GDestroyNotify) g_free);
+ g_list_free_full (def->superproperties, (GDestroyNotify) g_free);
+ g_list_free_full (def->subproperties, (GDestroyNotify) g_free);
g_free (def->max_cardinality);
g_free (def->description);
@@ -119,10 +119,11 @@ void
ttl_model_description_free (OntologyDescription *desc)
{
g_free (desc->title);
+ g_free (desc->description);
- g_list_foreach (desc->authors, (GFunc)g_free, NULL);
- g_list_foreach (desc->editors, (GFunc)g_free, NULL);
- g_list_foreach (desc->contributors, (GFunc)g_free, NULL);
+ g_list_free_full (desc->authors, (GDestroyNotify) g_free);
+ g_list_free_full (desc->editors, (GDestroyNotify) g_free);
+ g_list_free_full (desc->contributors, (GDestroyNotify) g_free);
g_free (desc->gitlog);
g_free (desc->upstream);
diff --git a/docs/tools/ttl_sgml.c b/docs/tools/ttl_sgml.c
index 2c1063a29..7f08ca4d8 100644
--- a/docs/tools/ttl_sgml.c
+++ b/docs/tools/ttl_sgml.c
@@ -157,6 +157,7 @@ ttl_sgml_print (OntologyDescription *description,
path = g_file_get_path (file);
f = fopen (path, "w");
g_assert (f != NULL);
+ g_free (path);
upper_name = g_ascii_strup (description->localPrefix, -1);
print_sgml_header (f, description);
diff --git a/docs/tools/ttlresource2sgml.c b/docs/tools/ttlresource2sgml.c
index b2ca3f1e3..fe8b6f42b 100644
--- a/docs/tools/ttlresource2sgml.c
+++ b/docs/tools/ttlresource2sgml.c
@@ -42,9 +42,10 @@ class_get_parent_hierarchy (Ontology *ontology,
*list = g_list_prepend (*list, (gpointer) class_name);
klass = g_hash_table_lookup (ontology->classes, class_name);
+
if (!klass) {
klass = ttl_model_class_new (class_name);
- g_hash_table_insert (ontology->classes, klass->classname, klass);
+ g_hash_table_insert (ontology->classes, g_strdup (klass->classname), klass);
return;
}
@@ -194,6 +195,7 @@ print_fts_properties (FILE *f,
g_fprintf (f, "</itemizedlist></para></refsect1>\n");
g_free (shortname);
g_free (id);
+ g_list_free (fts_props);
}
typedef struct {
@@ -310,6 +312,7 @@ hierarchy_context_new (OntologyClass *klass,
static void
hierarchy_context_free (HierarchyContext *context)
{
+ g_list_free (context->hierarchy);
g_ptr_array_unref (context->strings);
g_hash_table_unref (context->placed);
g_hash_table_unref (context->resolved_parents);
@@ -505,7 +508,7 @@ class_get_parent_hierarchy_strings (OntologyClass *klass,
{
HierarchyContext *context;
GList *c;
- GPtrArray *strings;
+ GPtrArray *strings = NULL;
context = hierarchy_context_new (klass, ontology);
@@ -619,7 +622,7 @@ print_properties (FILE *f,
if (!superprop) {
superprop = ttl_model_property_new (l->data);
- g_hash_table_insert (ontology->properties, superprop->propertyname,
superprop);
+ g_hash_table_insert (ontology->properties, g_strdup
(superprop->propertyname), superprop);
}
if (!superprop->domain)
@@ -692,6 +695,7 @@ generate_ontology_class_docs (Ontology *ontology,
child = g_file_get_child (output_dir, class_filename);
output_file = g_file_get_path (child);
+ g_object_unref (child);
f = fopen (output_file, "w");
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]