** Fixes bug #469657
authorMatthew Barnes <mbarnes@redhat.com>
Wed, 3 Oct 2007 18:48:07 +0000 (18:48 +0000)
committerMatthew Barnes <mbarnes@src.gnome.org>
Wed, 3 Oct 2007 18:48:07 +0000 (18:48 +0000)
2007-10-03  Matthew Barnes  <mbarnes@redhat.com>

** Fixes bug #469657

* addressbook/backends/vcf/e-book-backend-vcf.c:
* addressbook/libedata-book/e-data-book-factory.c:
* calendar/libedata-cal/e-cal-backend-cache.c:
* libedataserverui/e-passwords.c:
Use destroy functions in GHashTables to simplify memory management.

svn path=/trunk/; revision=8104

addressbook/ChangeLog
addressbook/backends/vcf/e-book-backend-vcf.c
addressbook/libedata-book/e-data-book-factory.c
calendar/ChangeLog
calendar/libedata-cal/e-cal-backend-cache.c
libedataserverui/ChangeLog
libedataserverui/e-passwords.c

index 04a4386..86a7f32 100644 (file)
@@ -1,3 +1,11 @@
+2007-10-03  Matthew Barnes  <mbarnes@redhat.com>
+
+       ** Fixes part of bug #469657
+
+       * backends/vcf/e-book-backend-vcf.c:
+       * libedata-book/e-data-book-factory.c:
+       Use destroy functions in GHashTables to simplify memory management.
+
 2007-10-01  Kjartan Maraas  <kmaraas@gnome.org>
 
        * backends/groupwise/e-book-backend-groupwise.c:
index dcd964a..7792506 100644 (file)
@@ -299,23 +299,19 @@ e_book_backend_vcf_remove_contacts (EBookBackendSync *backend,
        EBookBackendVCF *bvcf = E_BOOK_BACKEND_VCF (backend);
        char *id = id_list->data;
        GList *elem;
-       gboolean success;
-       char *real_id;
 
        g_mutex_lock (bvcf->priv->mutex);
-       success = g_hash_table_lookup_extended (bvcf->priv->contacts, id, (gpointer)&real_id, (gpointer)&elem);
-       if (!success) {
+       elem = g_hash_table_lookup (bvcf->priv->contacts, id);
+       if (!elem) {
                g_mutex_unlock (bvcf->priv->mutex);
                return GNOME_Evolution_Addressbook_ContactNotFound;
        }
 
-       success = g_hash_table_remove (bvcf->priv->contacts, real_id);
-       if (!success) {
+       if (!g_hash_table_remove (bvcf->priv->contacts, id)) {
                g_mutex_unlock (bvcf->priv->mutex);
                return GNOME_Evolution_Addressbook_ContactNotFound;
        }
 
-       g_free (real_id);
        g_free (elem->data);
        bvcf->priv->contact_list = g_list_remove_link (bvcf->priv->contact_list, elem);
 
@@ -338,19 +334,16 @@ e_book_backend_vcf_modify_contact (EBookBackendSync *backend,
                                   EContact **contact)
 {
        EBookBackendVCF *bvcf = E_BOOK_BACKEND_VCF (backend);
-       char *old_id;
        GList *elem;
        const char *id;
-       gboolean success;
 
        /* create a new ecard from the request data */
        *contact = e_contact_new_from_vcard (vcard);
        id = e_contact_get_const (*contact, E_CONTACT_UID);
 
        g_mutex_lock (bvcf->priv->mutex);
-       success = g_hash_table_lookup_extended (bvcf->priv->contacts, id, (gpointer)&old_id, (gpointer)&elem);
-
-       if (!success) {
+       elem = g_hash_table_lookup (bvcf->priv->contacts, id);
+       if (!elem) {
                g_mutex_unlock (bvcf->priv->mutex);
                return GNOME_Evolution_Addressbook_ContactNotFound;
        }
@@ -611,7 +604,10 @@ e_book_backend_vcf_load_source (EBookBackend             *backend,
 
        fd = g_open (bvcf->priv->filename, O_RDWR | O_BINARY, 0);
 
-       bvcf->priv->contacts = g_hash_table_new (g_str_hash, g_str_equal);
+       bvcf->priv->contacts = g_hash_table_new_full (
+               g_str_hash, g_str_equal,
+               (GDestroyNotify) g_free,
+               (GDestroyNotify) NULL);
 
        if (fd != -1) {
                writable = TRUE;
@@ -737,7 +733,6 @@ e_book_backend_vcf_dispose (GObject *object)
                if (bvcf->priv->dirty)
                        save_file (bvcf);
 
-               g_hash_table_foreach (bvcf->priv->contacts, (GHFunc)g_free, NULL);
                g_hash_table_destroy (bvcf->priv->contacts);
                g_list_foreach (bvcf->priv->contact_list, (GFunc)g_free, NULL);
                g_list_free (bvcf->priv->contact_list);
index 3893fee..8122941 100644 (file)
@@ -218,23 +218,8 @@ backend_last_client_gone_cb (EBookBackend *backend, gpointer data)
                uri = NULL;
 
        if (uri) {
-               gpointer orig_key;
-               gboolean result;
-               char *orig_uri;
-
                g_mutex_lock (factory->priv->map_mutex);
-
-               result = g_hash_table_lookup_extended (factory->priv->active_server_map, uri,
-                                                      &orig_key, NULL);
-               g_assert (result != FALSE);
-
-               orig_uri = orig_key;
-
-               g_hash_table_remove (factory->priv->active_server_map, orig_uri);
-               g_free (orig_uri);
-
-               g_object_unref (backend);
-
+               g_hash_table_remove (factory->priv->active_server_map, uri);
                g_mutex_unlock (factory->priv->map_mutex);
        }
 
@@ -501,72 +486,61 @@ e_data_book_factory_set_backend_mode (EDataBookFactory *factory, int mode)
 static void
 e_data_book_factory_init (EDataBookFactory *factory)
 {
+       GHashTable *active_server_map;
+       GHashTable *backends;
+
+       active_server_map = g_hash_table_new_full (
+               g_str_hash, g_str_equal,
+               (GDestroyNotify) g_free,
+               (GDestroyNotify) g_object_unref);
+
+       backends = g_hash_table_new_full (
+               g_str_hash, g_str_equal,
+               (GDestroyNotify) g_free,
+               (GDestroyNotify) NULL);
+
        factory->priv = g_new0 (EDataBookFactoryPrivate, 1);
 
        factory->priv->map_mutex         = g_mutex_new();
-       factory->priv->active_server_map = g_hash_table_new (g_str_hash, g_str_equal);
-       factory->priv->backends          = g_hash_table_new (g_str_hash, g_str_equal);
+       factory->priv->active_server_map = active_server_map;
+       factory->priv->backends          = backends;
        factory->priv->registered        = FALSE;
 }
 
 static void
-free_active_server_map_entry (gpointer key, gpointer value, gpointer data)
+e_data_book_factory_dispose (GObject *object)
 {
-       char *uri;
-       EBookBackend *backend;
-
-       uri = key;
-       g_free (uri);
+       EDataBookFactory *factory = E_DATA_BOOK_FACTORY (object);
+       EDataBookFactoryPrivate *priv = factory->priv;
 
-       backend = E_BOOK_BACKEND (value);
-       g_object_unref (backend);
-}
+       g_hash_table_remove_all (priv->active_server_map);
+       g_hash_table_remove_all (priv->backends);
 
-static void
-remove_backends_entry (gpointer key, gpointer value, gpointer data)
-{
-       char *uri;
+       if (priv->registered) {
+               bonobo_activation_active_server_unregister (
+                       priv->iid, bonobo_object_corba_objref (
+                       BONOBO_OBJECT (factory)));
+               priv->registered = FALSE;
+       }
 
-       uri = key;
-       g_free (uri);
+       if (G_OBJECT_CLASS (e_data_book_factory_parent_class)->dispose)
+               G_OBJECT_CLASS (e_data_book_factory_parent_class)->dispose (object);
 }
 
 static void
-e_data_book_factory_dispose (GObject *object)
+e_data_book_factory_finalize (GObject *object)
 {
        EDataBookFactory *factory = E_DATA_BOOK_FACTORY (object);
+       EDataBookFactoryPrivate *priv = factory->priv;
 
-       if (factory->priv) {
-               EDataBookFactoryPrivate *priv = factory->priv;
-
-               g_mutex_free (priv->map_mutex);
-
-               g_hash_table_foreach (priv->active_server_map,
-                                     free_active_server_map_entry,
-                                     NULL);
-               g_hash_table_destroy (priv->active_server_map);
-               priv->active_server_map = NULL;
-
-               g_hash_table_foreach (priv->backends,
-                                     remove_backends_entry,
-                                     NULL);
-               g_hash_table_destroy (priv->backends);
-               priv->backends = NULL;
-
-               if (priv->registered) {
-                       bonobo_activation_active_server_unregister (priv->iid,
-                                                           bonobo_object_corba_objref (BONOBO_OBJECT (factory)));
-                       priv->registered = FALSE;
-               }
-
-               g_free (priv->iid);
-       
-               g_free (priv);
-               factory->priv = NULL;
-       }
+       g_mutex_free (priv->map_mutex);
+       g_hash_table_destroy (priv->active_server_map);
+       g_hash_table_destroy (priv->backends);
+       g_free (priv->iid);
+       g_free (priv);
 
-       if (G_OBJECT_CLASS (e_data_book_factory_parent_class)->dispose)
-               G_OBJECT_CLASS (e_data_book_factory_parent_class)->dispose (object);
+       if (G_OBJECT_CLASS (e_data_book_factory_parent_class)->finalize)
+               G_OBJECT_CLASS (e_data_book_factory_parent_class)->finalize (object);
 }
 
 static void
@@ -578,6 +552,7 @@ e_data_book_factory_class_init (EDataBookFactoryClass *klass)
        e_data_book_factory_parent_class = g_type_class_peek_parent (klass);
 
        object_class->dispose = e_data_book_factory_dispose;
+       object_class->finalize = e_data_book_factory_finalize;
 
        factory_signals[LAST_BOOK_GONE] =
                g_signal_new ("last_book_gone",
index ac11642..d3549c1 100644 (file)
@@ -1,3 +1,10 @@
+2007-10-03  Matthew Barnes  <mbarnes@redhat.com>
+
+       ** Fixes part of bug #469657
+
+       * libedata-cal/e-cal-backend-cache.c:
+       Use destroy functions in GHashTables to simplify memory management.
+
 2007-09-27  Matthew Barnes  <mbarnes@redhat.com>
 
        ** Fixes part of bug #474000
index ad16ec6..66588e5 100644 (file)
@@ -140,13 +140,6 @@ e_cal_backend_cache_get_property (GObject *object, guint property_id, GValue *va
 }
 
 static void
-free_timezone_hash (gpointer key, gpointer value, gpointer user_data)
-{
-       g_free (key);
-       icaltimezone_free (value, 1);
-}
-
-static void
 e_cal_backend_cache_finalize (GObject *object)
 {
        ECalBackendCache *cache;
@@ -161,11 +154,8 @@ e_cal_backend_cache_finalize (GObject *object)
                        priv->uri = NULL;
                }
 
-               if (priv->timezones) {
-                       g_hash_table_foreach (priv->timezones, (GHFunc) free_timezone_hash, NULL);
-                       g_hash_table_destroy (priv->timezones);
-                       priv->timezones = NULL;
-               }
+               g_hash_table_destroy (priv->timezones);
+               priv->timezones = NULL;
 
                g_free (priv);
                cache->priv = NULL;
@@ -234,12 +224,21 @@ e_cal_backend_cache_class_init (ECalBackendCacheClass *klass)
 }
 
 static void
+timezones_value_destroy (icaltimezone *zone)
+{
+       icaltimezone_free (zone, 1);
+}
+
+static void
 e_cal_backend_cache_init (ECalBackendCache *cache)
 {
        ECalBackendCachePrivate *priv;
 
        priv = g_new0 (ECalBackendCachePrivate, 1);
-       priv->timezones = g_hash_table_new (g_str_hash, g_str_equal);
+       priv->timezones = g_hash_table_new_full (
+               g_str_hash, g_str_equal,
+               (GDestroyNotify) g_free,
+               (GDestroyNotify) timezones_value_destroy);
 
        cache->priv = priv;
 
@@ -602,7 +601,6 @@ gboolean
 e_cal_backend_cache_put_timezone (ECalBackendCache *cache, const icaltimezone *zone)
 {
        ECalBackendCachePrivate *priv;
-       gpointer orig_key, orig_value;
        icaltimezone *new_zone;
        icalcomponent *icalcomp;
        gboolean retval;
@@ -630,15 +628,6 @@ e_cal_backend_cache_put_timezone (ECalBackendCache *cache, const icaltimezone *z
        if (!retval)
                return FALSE;
 
-       /* check if the timezone already exists */
-       if (g_hash_table_lookup_extended (priv->timezones, icaltimezone_get_tzid ((icaltimezone *)zone),
-                                         &orig_key, &orig_value)) {
-               /* remove the previous timezone */
-               g_hash_table_remove (priv->timezones, orig_key);
-               g_free (orig_key);
-               icaltimezone_free (orig_value, 1);
-       }
-
        /* add the timezone to the hash table */
        new_zone = icaltimezone_new ();
        icaltimezone_set_component (new_zone, icalcomponent_new_clone (icalcomp));
@@ -740,7 +729,6 @@ e_cal_backend_cache_get_default_timezone (ECalBackendCache *cache)
 gboolean
 e_cal_backend_cache_remove_timezone (ECalBackendCache *cache, const char *tzid)
 {
-       gpointer orig_key, orig_value;
        ECalBackendCachePrivate *priv;
 
        g_return_val_if_fail (E_IS_CAL_BACKEND_CACHE (cache), FALSE);
@@ -748,11 +736,7 @@ e_cal_backend_cache_remove_timezone (ECalBackendCache *cache, const char *tzid)
 
        priv = cache->priv;
 
-       if (g_hash_table_lookup_extended (priv->timezones, tzid, &orig_key, &orig_value)) {
-               g_hash_table_remove (priv->timezones, tzid);
-               g_free (orig_key);
-               icaltimezone_free (orig_value, 1);
-       }
+       g_hash_table_remove (priv->timezones, tzid);
 
        return e_file_cache_remove_object (E_FILE_CACHE (cache), tzid);
 }
index 62515d9..69c6f3c 100644 (file)
@@ -1,3 +1,10 @@
+2007-10-03  Matthew Barnes  <mbarnes@redhat.com>
+
+       ** Fixes part of bug #469657
+
+       * e-passwords.c:
+       Use destroy functions in GHashTables to simplify memory management.
+
 2007-09-27  Matthew Barnes  <mbarnes@redhat.com>
 
        ** Fixes part of bug #474000
index 86f6a02..1803f8a 100644 (file)
@@ -381,13 +381,14 @@ password_path (const char *component_name, const char *key)
 static void
 ep_remember_password_keyring(EPassMsg *msg)
 {
-       gpointer okey, value;
+       gchar *value;
 
-       if (g_hash_table_lookup_extended (passwords, msg->key, &okey, &value)) {
+       value = g_hash_table_lookup (passwords, msg->key);
+       if (value != NULL) {
                /* add it to the on-disk cache of passwords */
                GnomeKeyringAttributeList *attributes;
                GnomeKeyringResult result;
-               EUri *uri = e_uri_new (okey);
+               EUri *uri = e_uri_new (msg->key);
                guint32 item_id;
 
                if (!strcmp (uri->protocol, "ldap") && !uri->user) {
@@ -420,8 +421,6 @@ ep_remember_password_keyring(EPassMsg *msg)
 
                /* now remove it from our session hash */
                g_hash_table_remove (passwords, msg->key);
-               g_free (okey);
-               g_free (value);
                
                e_uri_free (uri);
        }
@@ -434,12 +433,12 @@ ep_remember_password_keyring(EPassMsg *msg)
 static void
 ep_remember_password_file(EPassMsg *msg)
 {
-       gpointer okey, value;
-       char *path, *pass64;
+       char *path, *pass64, *value;
 
-       if (g_hash_table_lookup_extended (passwords, msg->key, &okey, &value)) {
+       value = g_hash_table_lookup (passwords, msg->key);
+       if (value != NULL) {
                /* add it to the on-disk cache of passwords */
-               path = password_path (msg->component, okey);
+               path = password_path (msg->component, msg->key);
                pass64 = ep_password_encode (value);
 
                gnome_config_private_set_string (path, pass64);
@@ -448,8 +447,6 @@ ep_remember_password_file(EPassMsg *msg)
 
                /* now remove it from our session hash */
                g_hash_table_remove (passwords, msg->key);
-               g_free (okey);
-               g_free (value);
 
                gnome_config_private_sync_file ("/Evolution");
        }
@@ -466,7 +463,6 @@ ep_forget_password_keyring (EPassMsg *msg)
        GnomeKeyringResult result;
        GList *matches = NULL, *tmp;    
        char *default_keyring = NULL;   
-       gpointer okey, value;
        EUri *uri = e_uri_new (msg->key);
 
        if (!strcmp (uri->protocol, "ldap") && !uri->user) {
@@ -480,12 +476,7 @@ ep_forget_password_keyring (EPassMsg *msg)
                uri->user = keycopy;
        }
            
-       if (g_hash_table_lookup_extended (passwords, msg->key, &okey, &value)) {
-               g_hash_table_remove (passwords, msg->key);
-               memset (value, 0, strlen (value));
-               g_free (okey);
-               g_free (value);
-       }
+       g_hash_table_remove (passwords, msg->key);
 
        if (!uri->host && !uri->user)
                /* No need to remove from keyring for pass phrases */
@@ -554,15 +545,9 @@ exit:
 static void
 ep_forget_password_file (EPassMsg *msg)
 {
-       gpointer okey, value;
        char *path;
 
-       if (g_hash_table_lookup_extended (passwords, msg->key, &okey, &value)) {
-               g_hash_table_remove (passwords, msg->key);
-               memset (value, 0, strlen (value));
-               g_free (okey);
-               g_free (value);
-       }
+       g_hash_table_remove (passwords, msg->key);
 
        /* clear it in the on disk db */
        path = password_path (msg->component, msg->key);
@@ -683,14 +668,6 @@ ep_get_password_file (EPassMsg *msg)
 static void
 ep_add_password (EPassMsg *msg)
 {
-       gpointer okey, value;
-
-       if (g_hash_table_lookup_extended (passwords, msg->key, &okey, &value)) {
-               g_hash_table_remove (passwords, msg->key);
-               g_free (okey);
-               g_free (value);
-       }
-
        g_hash_table_insert (passwords, g_strdup (msg->key), g_strdup (msg->oldpass));
 
        if (!msg->noreply)
@@ -875,7 +852,10 @@ e_passwords_init (void)
 
        if (!passwords) {
                /* create the per-session hash table */
-               passwords = g_hash_table_new (g_str_hash, g_str_equal);
+               passwords = g_hash_table_new_full (
+                       g_str_hash, g_str_equal,
+                       (GDestroyNotify) g_free,
+                       (GDestroyNotify) g_free);
 #ifdef ENABLE_THREADS
                main_thread = pthread_self();
 #endif