aboutsummaryrefslogtreecommitdiffstats
path: root/widgets/table/e-table-extras.c
diff options
context:
space:
mode:
authorMatthew Barnes <mbarnes@redhat.com>2007-10-02 19:54:42 +0800
committerMatthew Barnes <mbarnes@src.gnome.org>2007-10-02 19:54:42 +0800
commit09d4af6fff63dd112b8bb42087f14f7018e2f78c (patch)
tree991537a9ea1d8487334f6fb299098daf425f9db8 /widgets/table/e-table-extras.c
parent79521efaeecfbaf717e465670fcd2724aea53578 (diff)
downloadgsoc2013-evolution-09d4af6fff63dd112b8bb42087f14f7018e2f78c.tar
gsoc2013-evolution-09d4af6fff63dd112b8bb42087f14f7018e2f78c.tar.gz
gsoc2013-evolution-09d4af6fff63dd112b8bb42087f14f7018e2f78c.tar.bz2
gsoc2013-evolution-09d4af6fff63dd112b8bb42087f14f7018e2f78c.tar.lz
gsoc2013-evolution-09d4af6fff63dd112b8bb42087f14f7018e2f78c.tar.xz
gsoc2013-evolution-09d4af6fff63dd112b8bb42087f14f7018e2f78c.tar.zst
gsoc2013-evolution-09d4af6fff63dd112b8bb42087f14f7018e2f78c.zip
** Fixes bug #469657
2007-10-02 Matthew Barnes <mbarnes@redhat.com> ** Fixes bug #469657 * addressbook/importers/evolution-ldif-importer.c: * calendar/gui/comp-editor-factory.c: * composer/e-msg-composer.c: * e-util/e-config-listener.c: * mail/em-composer-prefs.c: * mail/em-folder-tree-model.c: * mail/em-format.c: * mail/em-format-html.c: * mail/em-migrate.c: * mail/em-subscribe-editor.c: * mail/mail-component.c: * mail/mail-send-recv.c: * mail/message-list.c: * mail/importers/elm-importer.c: * plugins/exchange-operations/exchange-folder-size-display.c: * plugins/mono/mono-plugin.c: * shell/e-shell-settings-dialog.c: * tools/killev.c: * widgets/table/e-table-extras.c: * widgets/table/e-table-selection-model.c: Use destroy functions in GHashTables to simplify memory management. svn path=/trunk/; revision=34344
Diffstat (limited to 'widgets/table/e-table-extras.c')
-rw-r--r--widgets/table/e-table-extras.c89
1 files changed, 30 insertions, 59 deletions
diff --git a/widgets/table/e-table-extras.c b/widgets/table/e-table-extras.c
index 312e19a0c5..25fb69e322 100644
--- a/widgets/table/e-table-extras.c
+++ b/widgets/table/e-table-extras.c
@@ -44,16 +44,6 @@
G_DEFINE_TYPE (ETableExtras, ete, G_TYPE_OBJECT)
static void
-cell_hash_free(gchar *key,
- ECell *cell,
- gpointer user_data)
-{
- g_free(key);
- if (cell)
- g_object_unref(cell);
-}
-
-static void
pixbuf_hash_free(gchar *key,
GdkPixbuf *pixbuf,
gpointer user_data)
@@ -69,30 +59,25 @@ ete_finalize (GObject *object)
ETableExtras *ete = E_TABLE_EXTRAS (object);
if (ete->cells) {
- g_hash_table_foreach (ete->cells, (GHFunc) cell_hash_free, NULL);
g_hash_table_destroy (ete->cells);
+ ete->cells = NULL;
}
if (ete->compares) {
- g_hash_table_foreach (ete->compares, (GHFunc) g_free, NULL);
g_hash_table_destroy (ete->compares);
+ ete->compares = NULL;
}
if (ete->searches) {
- g_hash_table_foreach (ete->searches, (GHFunc) g_free, NULL);
g_hash_table_destroy (ete->searches);
+ ete->searches = NULL;
}
if (ete->pixbufs) {
- g_hash_table_foreach (ete->pixbufs, (GHFunc) pixbuf_hash_free, NULL);
g_hash_table_destroy (ete->pixbufs);
+ ete->pixbufs = NULL;
}
- ete->cells = NULL;
- ete->compares = NULL;
- ete->searches = NULL;
- ete->pixbufs = NULL;
-
G_OBJECT_CLASS (ete_parent_class)->finalize (object);
}
@@ -162,12 +147,34 @@ e_string_search(gconstpointer haystack, const char *needle)
}
static void
+safe_unref (gpointer object)
+{
+ if (object != NULL)
+ g_object_unref (object);
+}
+
+static void
ete_init (ETableExtras *extras)
{
- extras->cells = g_hash_table_new(g_str_hash, g_str_equal);
- extras->compares = g_hash_table_new(g_str_hash, g_str_equal);
- extras->searches = g_hash_table_new(g_str_hash, g_str_equal);
- extras->pixbufs = g_hash_table_new(g_str_hash, g_str_equal);
+ extras->cells = g_hash_table_new_full (
+ g_str_hash, g_str_equal,
+ (GDestroyNotify) g_free,
+ (GDestroyNotify) safe_unref);
+
+ extras->compares = g_hash_table_new_full (
+ g_str_hash, g_str_equal,
+ (GDestroyNotify) g_free,
+ (GDestroyNotify) NULL);
+
+ extras->searches = g_hash_table_new_full (
+ g_str_hash, g_str_equal,
+ (GDestroyNotify) g_free,
+ (GDestroyNotify) NULL);
+
+ extras->pixbufs = g_hash_table_new_full (
+ g_str_hash, g_str_equal,
+ (GDestroyNotify) g_free,
+ (GDestroyNotify) safe_unref);
e_table_extras_add_compare(extras, "string", e_str_compare);
e_table_extras_add_compare(extras, "stringcase", e_str_case_compare);
@@ -199,16 +206,6 @@ e_table_extras_add_cell (ETableExtras *extras,
char *id,
ECell *cell)
{
- gchar *old_key;
- ECell *old_cell;
-
- if (g_hash_table_lookup_extended (extras->cells, id, (gpointer *)&old_key, (gpointer *)&old_cell)) {
- g_hash_table_remove (extras->cells, old_key);
- g_free (old_key);
- if (old_cell)
- g_object_unref (old_cell);
- }
-
if (cell)
g_object_ref_sink (cell);
g_hash_table_insert (extras->cells, g_strdup(id), cell);
@@ -226,14 +223,6 @@ e_table_extras_add_compare (ETableExtras *extras,
char *id,
GCompareFunc compare)
{
- gchar *old_key;
- GCompareFunc old_compare;
-
- if (g_hash_table_lookup_extended (extras->compares, id, (gpointer *)&old_key, (gpointer *)&old_compare)) {
- g_hash_table_remove (extras->compares, old_key);
- g_free (old_key);
- }
-
g_hash_table_insert(extras->compares, g_strdup(id), (gpointer) compare);
}
@@ -249,14 +238,6 @@ e_table_extras_add_search (ETableExtras *extras,
char *id,
ETableSearchFunc search)
{
- gchar *old_key;
- ETableSearchFunc old_search;
-
- if (g_hash_table_lookup_extended (extras->searches, id, (gpointer *)&old_key, (gpointer *)&old_search)) {
- g_hash_table_remove (extras->searches, old_key);
- g_free (old_key);
- }
-
g_hash_table_insert(extras->searches, g_strdup(id), search);
}
@@ -272,16 +253,6 @@ e_table_extras_add_pixbuf (ETableExtras *extras,
char *id,
GdkPixbuf *pixbuf)
{
- gchar *old_key;
- GdkPixbuf *old_pixbuf;
-
- if (g_hash_table_lookup_extended (extras->pixbufs, id, (gpointer *)&old_key, (gpointer *)&old_pixbuf)) {
- g_hash_table_remove (extras->cells, old_key);
- g_free (old_key);
- if (old_pixbuf)
- g_object_unref (old_pixbuf);
- }
-
if (pixbuf)
g_object_ref(pixbuf);
g_hash_table_insert (extras->pixbufs, g_strdup(id), pixbuf);