[planner] Fix memory leaks in loading of file reader/writer modules
- From: Maurice van der Pot <mvdpot src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [planner] Fix memory leaks in loading of file reader/writer modules
- Date: Tue, 24 Nov 2009 20:04:29 +0000 (UTC)
commit 6cc17b3de58f6b67ad7c1faf4e465636500c23b4
Author: Maurice van der Pot <griffon26 kfk4ever com>
Date: Tue Nov 3 22:05:10 2009 +0100
Fix memory leaks in loading of file reader/writer modules
libplanner/mrp-application.c | 28 ++++++++++++++++++++++++++--
libplanner/mrp-file-module.c | 6 +++++-
libplanner/mrp-file-module.h | 2 +-
src/planner-gantt-background.c | 13 ++++++++-----
src/planner-main.c | 4 ++++
5 files changed, 44 insertions(+), 9 deletions(-)
---
diff --git a/libplanner/mrp-application.c b/libplanner/mrp-application.c
index d3eb2d5..cd40fed 100644
--- a/libplanner/mrp-application.c
+++ b/libplanner/mrp-application.c
@@ -34,6 +34,7 @@
struct _MrpApplicationPriv {
GList *file_readers;
GList *file_writers;
+ GList *modules;
};
static void application_class_init (MrpApplicationClass *klass);
@@ -42,6 +43,8 @@ static void application_finalize (GObject *object);
static void application_init_gettext (void);
static void application_init_file_modules (MrpApplication *app);
+static void application_finalize_file_modules
+ (MrpApplication *app);
static GObjectClass *parent_class;
static guint last_used_id;
@@ -114,7 +117,12 @@ application_init (MrpApplication *app)
static void
application_finalize (GObject *object)
{
- /* FIXME: free stuff. */
+ MrpApplication *app = MRP_APPLICATION (object);
+
+ application_finalize_file_modules (app);
+
+ g_free (app->priv);
+ app->priv = NULL;
if (parent_class->finalize) {
parent_class->finalize (object);
@@ -138,7 +146,23 @@ application_init_gettext (void)
static void
application_init_file_modules (MrpApplication *app)
{
- mrp_file_module_load_all (app);
+ app->priv->modules = mrp_file_module_load_all (app);
+}
+
+static void
+application_finalize_file_modules (MrpApplication *app)
+{
+ g_list_foreach (app->priv->file_readers, (GFunc) g_free, NULL);
+ g_list_free (app->priv->file_readers);
+ app->priv->file_readers = NULL;
+
+ g_list_foreach (app->priv->file_writers, (GFunc) g_free, NULL);
+ g_list_free (app->priv->file_writers);
+ app->priv->file_writers = NULL;
+
+ g_list_foreach (app->priv->modules, (GFunc) g_free, NULL);
+ g_list_free (app->priv->modules);
+ app->priv->modules = NULL;
}
void
diff --git a/libplanner/mrp-file-module.c b/libplanner/mrp-file-module.c
index a3a2bac..04f7a90 100644
--- a/libplanner/mrp-file-module.c
+++ b/libplanner/mrp-file-module.c
@@ -48,13 +48,14 @@ file_module_load (const gchar *file)
return module;
}
-void
+GList *
mrp_file_module_load_all (MrpApplication *app)
{
GDir* dir;
const gchar *name;
MrpFileModule *module;
gchar *path;
+ GList *modules = NULL;
path = mrp_paths_get_file_modules_dir (NULL);
@@ -76,6 +77,7 @@ mrp_file_module_load_all (MrpApplication *app)
module = file_module_load (plugin);
if (module) {
mrp_file_module_init (module, app);
+ modules = g_list_prepend (modules, module);
}
g_free (plugin);
@@ -84,6 +86,8 @@ mrp_file_module_load_all (MrpApplication *app)
g_free (path);
g_dir_close (dir);
+
+ return modules;
}
MrpFileModule *
diff --git a/libplanner/mrp-file-module.h b/libplanner/mrp-file-module.h
index c60d335..6180eea 100644
--- a/libplanner/mrp-file-module.h
+++ b/libplanner/mrp-file-module.h
@@ -73,7 +73,7 @@ struct _MrpFileWriter {
const gchar * (*get_string) (MrpFileWriter *writer);
};
-void mrp_file_module_load_all (MrpApplication *app);
+GList * mrp_file_module_load_all (MrpApplication *app);
MrpFileModule * mrp_file_module_new (void);
diff --git a/src/planner-gantt-background.c b/src/planner-gantt-background.c
index 45930dd..4403127 100644
--- a/src/planner-gantt-background.c
+++ b/src/planner-gantt-background.c
@@ -433,21 +433,24 @@ gantt_background_unrealize (GnomeCanvasItem *item)
background = PLANNER_GANTT_BACKGROUND (item);
- gdk_gc_unref (background->priv->border_gc);
+ g_object_unref (background->priv->border_gc);
background->priv->border_gc = NULL;
- gdk_gc_unref (background->priv->fill_gc);
+ g_object_unref (background->priv->fill_gc);
background->priv->fill_gc = NULL;
- gdk_gc_unref (background->priv->timeline_gc);
+ g_object_unref (background->priv->timeline_gc);
background->priv->timeline_gc = NULL;
- gdk_gc_unref (background->priv->start_gc);
+ g_object_unref (background->priv->start_gc);
background->priv->start_gc = NULL;
- gdk_gc_unref (background->priv->guidelines_gc);
+ g_object_unref (background->priv->guidelines_gc);
background->priv->guidelines_gc = NULL;
+ g_object_unref (background->priv->layout);
+ background->priv->layout = NULL;
+
GNOME_CANVAS_ITEM_CLASS (parent_class)->unrealize (item);
}
diff --git a/src/planner-main.c b/src/planner-main.c
index 0a61f6d..02488c6 100644
--- a/src/planner-main.c
+++ b/src/planner-main.c
@@ -144,5 +144,9 @@ main (int argc, char **argv)
g_object_unref (application);
+#ifdef WITH_GNOME
+ g_object_unref (program);
+#endif
+
return 0;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]