[planner] Fix a few memory leaks
- From: Maurice van der Pot <mvdpot src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [planner] Fix a few memory leaks
- Date: Tue, 24 Nov 2009 20:04:19 +0000 (UTC)
commit 15c94a5eaf4092cfb4fb18722f0e12be60801ae6
Author: Maurice van der Pot <griffon26 kfk4ever com>
Date: Sat Oct 31 00:51:27 2009 +0100
Fix a few memory leaks
libplanner/mrp-application.c | 9 +++++++--
src/planner-gantt-chart.c | 14 ++++++++++++--
src/planner-main.c | 6 +++++-
src/planner-msp-plugin.c | 7 -------
src/planner-sql-plugin.c | 7 -------
src/planner-window.c | 7 ++++++-
6 files changed, 30 insertions(+), 20 deletions(-)
---
diff --git a/libplanner/mrp-application.c b/libplanner/mrp-application.c
index 3b67bb6..d3eb2d5 100644
--- a/libplanner/mrp-application.c
+++ b/libplanner/mrp-application.c
@@ -124,7 +124,12 @@ application_finalize (GObject *object)
static void
application_init_gettext (void)
{
- bindtextdomain (GETTEXT_PACKAGE, mrp_paths_get_locale_dir ());
+ gchar *locale_dir;
+
+ locale_dir = mrp_paths_get_locale_dir ();
+ bindtextdomain (GETTEXT_PACKAGE, locale_dir);
+ g_free(locale_dir);
+
bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
imrp_time_init ();
@@ -133,7 +138,7 @@ application_init_gettext (void)
static void
application_init_file_modules (MrpApplication *app)
{
- mrp_file_module_load_all (app);
+ mrp_file_module_load_all (app);
}
void
diff --git a/src/planner-gantt-chart.c b/src/planner-gantt-chart.c
index a0aabd3..d42b687 100644
--- a/src/planner-gantt-chart.c
+++ b/src/planner-gantt-chart.c
@@ -162,6 +162,8 @@ static void gantt_chart_row_inserted (GtkTreeModel *mod
GtkTreePath *path,
GtkTreeIter *iter,
gpointer data);
+static void gantt_chart_remove_children (PlannerGanttChart *chart,
+ TreeNode *node);
static void gantt_chart_row_deleted (GtkTreeModel *model,
GtkTreePath *path,
gpointer data);
@@ -474,6 +476,10 @@ gantt_chart_destroy (GtkObject *object)
planner_gantt_chart_set_model (chart, NULL);
/* FIXME: free more stuff. */
+ if (chart->priv->tree != NULL) {
+ gantt_chart_remove_children (chart, chart->priv->tree);
+ chart->priv->tree = NULL;
+ }
if (chart->priv->model != NULL) {
g_object_unref (chart->priv->model);
@@ -512,6 +518,8 @@ gantt_chart_style_set (GtkWidget *widget,
f = 0.2 * pango_font_metrics_get_approximate_char_width (metrics) / PANGO_SCALE;
+ pango_font_metrics_unref(metrics);
+
/* Re-layout with the new factor. */
gantt_chart_set_zoom (PLANNER_GANTT_CHART (widget), priv->zoom);
}
@@ -750,8 +758,10 @@ gantt_chart_remove_children (PlannerGanttChart *chart,
gantt_chart_remove_children (chart, node->children[i]);
}
- gtk_object_destroy (GTK_OBJECT (node->item));
- node->item = NULL;
+ if (node->item) {
+ gtk_object_destroy (GTK_OBJECT (node->item));
+ node->item = NULL;
+ }
node->task = NULL;
g_free (node->children);
diff --git a/src/planner-main.c b/src/planner-main.c
index 2b747cb..0a61f6d 100644
--- a/src/planner-main.c
+++ b/src/planner-main.c
@@ -58,8 +58,12 @@ main (int argc, char **argv)
{ NULL }
};
gchar *filename;
+ gchar *locale_dir;
+
+ locale_dir = mrp_paths_get_locale_dir ();
+ bindtextdomain (GETTEXT_PACKAGE, locale_dir);
+ g_free(locale_dir);
- bindtextdomain (GETTEXT_PACKAGE, mrp_paths_get_locale_dir ());
bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
textdomain (GETTEXT_PACKAGE);
diff --git a/src/planner-msp-plugin.c b/src/planner-msp-plugin.c
index f6e8bd9..8ee3f7c 100644
--- a/src/planner-msp-plugin.c
+++ b/src/planner-msp-plugin.c
@@ -35,10 +35,6 @@
#define CONF_MSP_PLUGIN_LAST_DIR "/plugins/msp_plugin/last_dir"
-typedef struct {
- GtkWidget *open_dialog;
-} MspPluginPriv;
-
static void msp_plugin_open (GtkAction *action,
gpointer user_data);
void plugin_init (PlannerPlugin *plugin,
@@ -269,13 +265,10 @@ G_MODULE_EXPORT void
plugin_init (PlannerPlugin *plugin,
PlannerWindow *main_window)
{
- MspPluginPriv *priv;
GtkActionGroup *actions;
GtkUIManager *ui;
gchar *filename;
- priv = g_new0 (MspPluginPriv, 1);
-
actions = gtk_action_group_new ("MSP plugin actions");
gtk_action_group_set_translation_domain (actions, GETTEXT_PACKAGE);
diff --git a/src/planner-sql-plugin.c b/src/planner-sql-plugin.c
index c130686..8ca001c 100644
--- a/src/planner-sql-plugin.c
+++ b/src/planner-sql-plugin.c
@@ -53,10 +53,6 @@
#define CONNECTION_FORMAT_STRING "HOST=%s;DB_NAME=%s"
-typedef struct {
- GtkWidget *open_dialog;
-} SQLPluginPriv;
-
static gint sql_plugin_retrieve_project_id (PlannerPlugin *plugin,
gchar *server,
gchar *port,
@@ -1230,7 +1226,6 @@ G_MODULE_EXPORT void
plugin_init (PlannerPlugin *plugin,
PlannerWindow *main_window)
{
- SQLPluginPriv *priv;
GtkActionGroup *actions;
GtkUIManager *ui;
gint i = -1;
@@ -1238,8 +1233,6 @@ plugin_init (PlannerPlugin *plugin,
gda_init (PACKAGE, VERSION, 0, NULL);
- priv = g_new0 (SQLPluginPriv, 1);
-
g_object_set_data (G_OBJECT (main_window),
PROJECT_ID,
GINT_TO_POINTER (i));
diff --git a/src/planner-window.c b/src/planner-window.c
index 8fe4cfd..c9494db 100644
--- a/src/planner-window.c
+++ b/src/planner-window.c
@@ -366,6 +366,8 @@ window_init (PlannerWindow *window)
priv = g_new0 (PlannerWindowPriv, 1);
window->priv = priv;
+ priv->views = NULL;
+
/* Setup drag-n-drop. */
gtk_drag_dest_set (GTK_WIDGET (window),
GTK_DEST_DEFAULT_ALL,
@@ -397,6 +399,10 @@ window_finalize (GObject *object)
PlannerWindow *window = PLANNER_WINDOW (object);
PlannerWindowPriv *priv = window->priv;
+ if (priv->views) {
+ g_list_foreach (priv->views, (GFunc) g_object_unref, NULL);
+ g_list_free (priv->views);
+ }
if (priv->application) {
g_object_unref (priv->application);
}
@@ -653,7 +659,6 @@ window_populate (PlannerWindow *window)
priv->view_actions = gtk_action_group_new ("View Actions");
gtk_ui_manager_insert_action_group (priv->ui_manager, priv->view_actions, 0);
- priv->views = NULL;
priv->views = g_list_append (priv->views, planner_gantt_view_new ());
priv->views = g_list_append (priv->views, planner_task_view_new ());
priv->views = g_list_append (priv->views, planner_resource_view_new ());
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]