Fix memory leaks in a number of places

This commit is contained in:
Christian Dywan 2009-04-05 23:46:15 +02:00
parent 3eae091ebb
commit eed273b35e
8 changed files with 52 additions and 6 deletions

View file

@ -68,6 +68,7 @@ statusbar_features_app_add_browser_cb (MidoriApp* app,
gtk_widget_show (button); gtk_widget_show (button);
gtk_widget_show (bbox); gtk_widget_show (bbox);
gtk_box_pack_start (GTK_BOX (statusbar), bbox, FALSE, FALSE, 3); gtk_box_pack_start (GTK_BOX (statusbar), bbox, FALSE, FALSE, 3);
g_object_unref (settings);
g_signal_connect (extension, "deactivate", g_signal_connect (extension, "deactivate",
G_CALLBACK (statusbar_features_deactivate_cb), bbox); G_CALLBACK (statusbar_features_deactivate_cb), bbox);

View file

@ -557,11 +557,12 @@ katze_net_load_icon (KatzeNet* net,
if (g_hash_table_lookup_extended (net->memory, if (g_hash_table_lookup_extended (net->memory,
icon_file, NULL, (gpointer)&pixbuf)) icon_file, NULL, (gpointer)&pixbuf))
{ {
g_free (icon_file);
if (pixbuf) if (pixbuf)
g_object_ref (pixbuf); g_object_ref (pixbuf);
} }
else if ((pixbuf = gdk_pixbuf_new_from_file (icon_file, NULL))) else if ((pixbuf = gdk_pixbuf_new_from_file (icon_file, NULL)))
; g_free (icon_file);
/* If the called doesn't provide an icon callback, /* If the called doesn't provide an icon callback,
we assume there is no interest in loading an un-cached icon. */ we assume there is no interest in loading an un-cached icon. */
else if (icon_cb) else if (icon_cb)

View file

@ -154,6 +154,7 @@ settings_new_from_file (const gchar* filename)
else else
g_warning (_("Invalid configuration value '%s'"), property); g_warning (_("Invalid configuration value '%s'"), property);
} }
g_free (pspecs);
return settings; return settings;
} }
@ -188,10 +189,11 @@ settings_save_to_file (MidoriWebSettings* settings,
} }
if (type == G_TYPE_PARAM_STRING) if (type == G_TYPE_PARAM_STRING)
{ {
const gchar* string; gchar* string;
g_object_get (settings, property, &string, NULL); g_object_get (settings, property, &string, NULL);
g_key_file_set_string (key_file, "settings", property, g_key_file_set_string (key_file, "settings", property,
string ? string : ""); string ? string : "");
g_free (string);
} }
else if (type == G_TYPE_PARAM_INT) else if (type == G_TYPE_PARAM_INT)
{ {
@ -224,6 +226,7 @@ settings_save_to_file (MidoriWebSettings* settings,
else else
g_warning (_("Invalid configuration value '%s'"), property); g_warning (_("Invalid configuration value '%s'"), property);
} }
g_free (pspecs);
saved = sokoke_key_file_save_to_file (key_file, filename, error); saved = sokoke_key_file_save_to_file (key_file, filename, error);
g_key_file_free (key_file); g_key_file_free (key_file);
return saved; return saved;
@ -266,6 +269,7 @@ search_engines_new_from_file (const gchar* filename,
} }
katze_array_add_item (search_engines, item); katze_array_add_item (search_engines, item);
} }
g_free (pspecs);
g_strfreev (engines); g_strfreev (engines);
g_key_file_free (key_file); g_key_file_free (key_file);
return search_engines; return search_engines;
@ -303,6 +307,7 @@ search_engines_save_to_file (KatzeArray* search_engines,
g_free (value); g_free (value);
} }
} }
g_free (pspecs);
saved = sokoke_key_file_save_to_file (key_file, filename, error); saved = sokoke_key_file_save_to_file (key_file, filename, error);
g_key_file_free (key_file); g_key_file_free (key_file);
@ -921,6 +926,8 @@ midori_app_add_browser_cb (MidoriApp* app,
addon = g_object_new (MIDORI_TYPE_EXTENSIONS, "app", app, NULL); addon = g_object_new (MIDORI_TYPE_EXTENSIONS, "app", app, NULL);
gtk_widget_show (addon); gtk_widget_show (addon);
midori_panel_append_page (MIDORI_PANEL (panel), MIDORI_VIEWABLE (addon)); midori_panel_append_page (MIDORI_PANEL (panel), MIDORI_VIEWABLE (addon));
g_object_unref (panel);
} }
static void static void
@ -1241,7 +1248,9 @@ midori_load_session (gpointer data)
katze_item_set_uri (item, homepage); katze_item_set_uri (item, homepage);
g_free (homepage); g_free (homepage);
} }
g_object_unref (settings);
katze_array_add_item (_session, item); katze_array_add_item (_session, item);
g_object_unref (item);
} }
session = midori_browser_get_proxy_array (browser); session = midori_browser_get_proxy_array (browser);
@ -1682,6 +1691,7 @@ main (int argc,
#if HAVE_SQLITE #if HAVE_SQLITE
settings = katze_object_get_object (app, "settings"); settings = katze_object_get_object (app, "settings");
g_object_get (settings, "maximum-history-age", &max_history_age, NULL); g_object_get (settings, "maximum-history-age", &max_history_age, NULL);
g_object_unref (settings);
midori_history_terminate (db, max_history_age); midori_history_terminate (db, max_history_age);
#endif #endif
g_object_unref (app); g_object_unref (app);

View file

@ -257,7 +257,8 @@ katze_item_to_data (KatzeItem* item)
markup = g_strdup_printf ("<folder%s>\n%s%s%s</folder>\n", markup = g_strdup_printf ("<folder%s>\n%s%s%s</folder>\n",
"" /* folded ? folded : "" */, "" /* folded ? folded : "" */,
title, desc, title, desc,
g_string_free (_markup, FALSE)); _markup->str);
g_string_free (_markup, TRUE);
/* g_free (folded); */ /* g_free (folded); */
g_free (title); g_free (title);
g_free (desc); g_free (desc);
@ -313,7 +314,8 @@ katze_array_to_xbel (KatzeArray* array,
"\"http://www.python.org/topics/xml/dtds/xbel-1.0.dtd\">\n", "\"http://www.python.org/topics/xml/dtds/xbel-1.0.dtd\">\n",
title, title,
desc, desc,
g_string_free (inner_markup, FALSE)); inner_markup->str);
g_string_free (inner_markup, TRUE);
g_free (title); g_free (title);
g_free (desc); g_free (desc);

View file

@ -883,6 +883,7 @@ midori_addons_new (MidoriAddonKind kind,
} }
g_signal_connect (monitor, "changed", g_signal_connect (monitor, "changed",
G_CALLBACK (midori_addons_directory_monitor_changed), addons); G_CALLBACK (midori_addons_directory_monitor_changed), addons);
g_object_unref (directory);
} }
g_slist_free (list); g_slist_free (list);

View file

@ -63,6 +63,9 @@ enum
PROP_APP PROP_APP
}; };
static void
midori_bookmarks_finalize (GObject* object);
static void static void
midori_bookmarks_set_property (GObject* object, midori_bookmarks_set_property (GObject* object,
guint prop_id, guint prop_id,
@ -82,6 +85,7 @@ midori_bookmarks_class_init (MidoriBookmarksClass* class)
GParamFlags flags; GParamFlags flags;
gobject_class = G_OBJECT_CLASS (class); gobject_class = G_OBJECT_CLASS (class);
gobject_class->finalize = midori_bookmarks_finalize;
gobject_class->set_property = midori_bookmarks_set_property; gobject_class->set_property = midori_bookmarks_set_property;
gobject_class->get_property = midori_bookmarks_get_property; gobject_class->get_property = midori_bookmarks_get_property;
@ -691,6 +695,7 @@ midori_bookmarks_open_in_tab_activate_cb (GtkWidget* menuitem,
settings = katze_object_get_object (browser, "settings"); settings = katze_object_get_object (browser, "settings");
if (!katze_object_get_boolean (settings, "open-tabs-in-the-background")) if (!katze_object_get_boolean (settings, "open-tabs-in-the-background"))
midori_browser_set_current_page (MIDORI_BROWSER (browser), n); midori_browser_set_current_page (MIDORI_BROWSER (browser), n);
g_object_unref (settings);
} }
i++; i++;
} }
@ -707,6 +712,7 @@ midori_bookmarks_open_in_tab_activate_cb (GtkWidget* menuitem,
settings = katze_object_get_object (browser, "settings"); settings = katze_object_get_object (browser, "settings");
if (!katze_object_get_boolean (settings, "open-tabs-in-the-background")) if (!katze_object_get_boolean (settings, "open-tabs-in-the-background"))
midori_browser_set_current_page (MIDORI_BROWSER (browser), n); midori_browser_set_current_page (MIDORI_BROWSER (browser), n);
g_object_unref (settings);
} }
} }
} }
@ -888,7 +894,6 @@ midori_bookmarks_init (MidoriBookmarks* bookmarks)
GtkCellRenderer* renderer_text; GtkCellRenderer* renderer_text;
bookmarks->net = katze_net_new (); bookmarks->net = katze_net_new ();
/* FIXME: Dereference the net on finalization */
/* Create the treeview */ /* Create the treeview */
model = gtk_tree_store_new (1, KATZE_TYPE_ITEM); model = gtk_tree_store_new (1, KATZE_TYPE_ITEM);
@ -926,6 +931,16 @@ midori_bookmarks_init (MidoriBookmarks* bookmarks)
bookmarks->treeview = treeview; bookmarks->treeview = treeview;
} }
static void
midori_bookmarks_finalize (GObject* object)
{
MidoriBookmarks* bookmarks = MIDORI_BOOKMARKS (object);
if (bookmarks->app)
g_object_unref (bookmarks->app);
g_object_unref (bookmarks->net);
}
/** /**
* midori_bookmarks_new: * midori_bookmarks_new:
* *

View file

@ -64,6 +64,9 @@ enum
PROP_APP PROP_APP
}; };
static void
midori_history_finalize (GObject* object);
static void static void
midori_history_set_property (GObject* object, midori_history_set_property (GObject* object,
guint prop_id, guint prop_id,
@ -83,6 +86,7 @@ midori_history_class_init (MidoriHistoryClass* class)
GParamFlags flags; GParamFlags flags;
gobject_class = G_OBJECT_CLASS (class); gobject_class = G_OBJECT_CLASS (class);
gobject_class->finalize = midori_history_finalize;
gobject_class->set_property = midori_history_set_property; gobject_class->set_property = midori_history_set_property;
gobject_class->get_property = midori_history_get_property; gobject_class->get_property = midori_history_get_property;
@ -495,7 +499,6 @@ midori_history_set_app (MidoriHistory* history,
time_t now = time (NULL); time_t now = time (NULL);
gint64 day = sokoke_time_t_to_julian (&now); gint64 day = sokoke_time_t_to_julian (&now);
/* FIXME: Dereference the app on finalization */
model = gtk_tree_view_get_model (GTK_TREE_VIEW (history->treeview)); model = gtk_tree_view_get_model (GTK_TREE_VIEW (history->treeview));
midori_history_insert_item (history, GTK_TREE_STORE (model), midori_history_insert_item (history, GTK_TREE_STORE (model),
NULL, KATZE_ITEM (g_object_ref (history->array)), day); NULL, KATZE_ITEM (g_object_ref (history->array)), day);
@ -721,6 +724,7 @@ midori_history_open_in_tab_activate_cb (GtkWidget* menuitem,
settings = katze_object_get_object (browser, "settings"); settings = katze_object_get_object (browser, "settings");
if (!katze_object_get_boolean (settings, "open-tabs-in-the-background")) if (!katze_object_get_boolean (settings, "open-tabs-in-the-background"))
midori_browser_set_current_page (MIDORI_BROWSER (browser), n); midori_browser_set_current_page (MIDORI_BROWSER (browser), n);
g_object_unref (settings);
} }
i++; i++;
} }
@ -737,6 +741,7 @@ midori_history_open_in_tab_activate_cb (GtkWidget* menuitem,
settings = katze_object_get_object (browser, "settings"); settings = katze_object_get_object (browser, "settings");
if (!katze_object_get_boolean (settings, "open-tabs-in-the-background")) if (!katze_object_get_boolean (settings, "open-tabs-in-the-background"))
midori_browser_set_current_page (MIDORI_BROWSER (browser), n); midori_browser_set_current_page (MIDORI_BROWSER (browser), n);
g_object_unref (settings);
} }
} }
} }
@ -957,6 +962,16 @@ midori_history_init (MidoriHistory* history)
history->treeview = treeview; history->treeview = treeview;
} }
static void
midori_history_finalize (GObject* object)
{
MidoriHistory* history = MIDORI_HISTORY (object);
if (history->app)
g_object_unref (history->app);
g_object_unref (history->array);
}
/** /**
* midori_history_new: * midori_history_new:
* *

View file

@ -43,6 +43,7 @@ browser_create (void)
} }
g_list_free (actions); g_list_free (actions);
gtk_widget_destroy (GTK_WIDGET (browser)); gtk_widget_destroy (GTK_WIDGET (browser));
g_object_unref (app);
} }
int int