Blob Blame History Raw
From e1cdcccab0a3861d0c465cb4b75fede605a7ec17 Mon Sep 17 00:00:00 2001
From: Jakub Filak <jfilak@redhat.com>
Date: Sun, 25 Jan 2015 14:19:43 +0100
Subject: [PATCH] fix several memory leaks

I discovered these leaks while chasing a bug related to rhbz#1163579.

The most interesting one is the missing semicolon in src/lib/file_obj.c

Signed-off-by: Jakub Filak <jfilak@redhat.com>
---
 src/gtk-helpers/problem_details_widget.c |  1 +
 src/gui-wizard-gtk/main.c                |  7 ++++---
 src/gui-wizard-gtk/wizard.c              | 10 +++++++---
 src/lib/file_obj.c                       |  4 ++--
 src/lib/workflow.c                       |  4 +++-
 5 files changed, 17 insertions(+), 9 deletions(-)

diff --git a/src/gtk-helpers/problem_details_widget.c b/src/gtk-helpers/problem_details_widget.c
index c314d4d..fed65b2 100644
--- a/src/gtk-helpers/problem_details_widget.c
+++ b/src/gtk-helpers/problem_details_widget.c
@@ -305,6 +305,7 @@ problem_details_widget_populate(ProblemDetailsWidget *self)
             line = xasprintf("%s", uid ? uid : username);
 
         problem_details_widget_add_single_line(self, "user", line);
+        free(line);
     }
 
     { /* Type/Analyzer: CCpp */
diff --git a/src/gui-wizard-gtk/main.c b/src/gui-wizard-gtk/main.c
index 41a8089..9780c8d 100644
--- a/src/gui-wizard-gtk/main.c
+++ b/src/gui-wizard-gtk/main.c
@@ -195,9 +195,9 @@ int main(int argc, char **argv)
     load_workflow_config_data(WORKFLOWS_DIR);
 
     /* list of workflows applicable to the currently processed problem */
-    GHashTable *possible_workflows = load_workflow_config_data_from_list(
-                list_possible_events_glist(g_dump_dir_name, "workflow"),
-                WORKFLOWS_DIR);
+    GList *possible_names = list_possible_events_glist(g_dump_dir_name, "workflow");
+    GHashTable *possible_workflows = load_workflow_config_data_from_list(possible_names, WORKFLOWS_DIR);
+    g_list_free_full(possible_names, free);
 
     /* if we have only 1 workflow, we can use the events from it as default */
     if (!expert_mode && g_auto_event_list == NULL && g_hash_table_size(possible_workflows) == 1)
@@ -212,6 +212,7 @@ int main(int argc, char **argv)
             g_auto_event_list = wf_get_event_names((workflow_t *)value);
         }
     }
+    g_hash_table_destroy(possible_workflows);
 
     problem_data_reload_from_dump_dir();
 
diff --git a/src/gui-wizard-gtk/wizard.c b/src/gui-wizard-gtk/wizard.c
index ab6123f..513f0a3 100644
--- a/src/gui-wizard-gtk/wizard.c
+++ b/src/gui-wizard-gtk/wizard.c
@@ -2424,14 +2424,14 @@ static bool highligh_words_in_textview(int page, GtkTextView *tev, GList *words,
                 SEARCH_COLUMN_ITEM, &word,
                 -1);
 
+        free(text);
+
         if (word->buffer == buffer)
         {
             buffer_removing = true;
 
             valid = gtk_list_store_remove(g_ls_sensitive_list, &iter);
 
-            free(text);
-
             if (word == g_current_highlighted_word)
                 g_current_highlighted_word = NULL;
 
@@ -2794,9 +2794,12 @@ static void add_workflow_buttons(GtkBox *box, GHashTable *workflows, GCallback f
 {
     gtk_container_foreach(GTK_CONTAINER(box), &remove_child_widget, NULL);
 
+    GList *possible_workflows = list_possible_events_glist(g_dump_dir_name, "workflow");
     GHashTable *workflow_table = load_workflow_config_data_from_list(
-                        list_possible_events_glist(g_dump_dir_name, "workflow"),
+                        possible_workflows,
                         WORKFLOWS_DIR);
+    g_list_free_full(possible_workflows, free);
+    g_object_set_data_full(G_OBJECT(box), "workflows", workflow_table, (GDestroyNotify)g_hash_table_destroy);
 
     GList *wf_list = g_hash_table_get_values(workflow_table);
     wf_list = g_list_sort(wf_list, (GCompareFunc)wf_priority_compare);
@@ -2817,6 +2820,7 @@ static void add_workflow_buttons(GtkBox *box, GHashTable *workflows, GCallback f
         gtk_widget_set_margin_start(label, 40);
 #endif
         gtk_widget_set_margin_bottom(label, 10);
+        g_list_free(children);
         free(btn_label);
         g_signal_connect(button, "clicked", func, w);
         gtk_box_pack_start(box, button, true, false, 2);
diff --git a/src/lib/file_obj.c b/src/lib/file_obj.c
index bbb5b9f..0821155 100644
--- a/src/lib/file_obj.c
+++ b/src/lib/file_obj.c
@@ -30,7 +30,7 @@ file_obj_t *new_file_obj(const char* fullpath, const char* filename)
 void free_file_obj(file_obj_t *f)
 {
     if (f == NULL)
-        return
+        return;
 
     free(f->fullpath);
     free(f->filename);
@@ -45,4 +45,4 @@ const char *fo_get_fullpath(file_obj_t *fo)
 const char *fo_get_filename(file_obj_t *fo)
 {
     return fo->filename;
-}
\ No newline at end of file
+}
diff --git a/src/lib/workflow.c b/src/lib/workflow.c
index c6eedf4..a985834 100644
--- a/src/lib/workflow.c
+++ b/src/lib/workflow.c
@@ -90,7 +90,7 @@ static void load_workflow_config(const char *name,
         workflow_t *workflow = new_workflow(file->filename);
         load_workflow_description_from_file(workflow, file->fullpath);
         log_notice("Adding '%s' to workflows\n", file->filename);
-        g_hash_table_insert(wf_list, file->filename, workflow);
+        g_hash_table_insert(wf_list, xstrdup(file->filename), workflow);
     }
 }
 
@@ -104,12 +104,14 @@ GHashTable *load_workflow_config_data_from_list(GList *wf_names,
                          g_free,
                          (GDestroyNotify) free_workflow
         );
+
     GList *workflow_files = get_file_list(path, "xml");
     while(wfs)
     {
         load_workflow_config((const char *)wfs->data, workflow_files, wf_list);
         wfs = g_list_next(wfs);
     }
+    free_file_list(workflow_files);
 
     return wf_list;
 }
-- 
2.1.0