+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:
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);
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;
}
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;
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);
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);
}
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
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",
+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
}
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;
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;
}
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;
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;
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));
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);
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);
}
+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
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) {
/* now remove it from our session hash */
g_hash_table_remove (passwords, msg->key);
- g_free (okey);
- g_free (value);
e_uri_free (uri);
}
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);
/* 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");
}
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) {
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 */
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);
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)
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