book_backend_ldap_finalize (GObject *object)
{
	EBookBackendLDAPPrivate *priv;

	priv = E_BOOK_BACKEND_LDAP_GET_PRIVATE (object);

	g_rec_mutex_lock (&eds_ldap_handler_lock);
	g_rec_mutex_lock (&priv->op_hash_mutex);
	g_hash_table_foreach_remove (priv->id_to_op, (GHRFunc) call_dtor, NULL);
	g_hash_table_destroy (priv->id_to_op);
	g_rec_mutex_unlock (&priv->op_hash_mutex);
	g_rec_mutex_unlock (&eds_ldap_handler_lock);
	g_rec_mutex_clear (&priv->op_hash_mutex);
	g_mutex_clear (&priv->view_mutex);

	/* Remove the timeout before unbinding to avoid a race. */
	if (priv->poll_timeout > 0) {
		g_source_remove (priv->poll_timeout);
		priv->poll_timeout = 0;
	}

	g_rec_mutex_lock (&eds_ldap_handler_lock);
	if (priv->ldap)
		ldap_unbind (priv->ldap);
	g_rec_mutex_unlock (&eds_ldap_handler_lock);

	g_slist_foreach (priv->supported_fields, (GFunc) g_free, NULL);
	g_slist_free (priv->supported_fields);

	g_slist_foreach (priv->supported_auth_methods, (GFunc) g_free, NULL);
	g_slist_free (priv->supported_auth_methods);

	g_free (priv->summary_file_name);

	if (priv->summary) {
		e_book_backend_summary_save (priv->summary);
		g_object_unref (priv->summary);
		priv->summary = NULL;
	}

	if (priv->cache) {
		g_object_unref (priv->cache);
		priv->cache = NULL;
	}

	g_free (priv->ldap_host);
	g_free (priv->ldap_rootdn);
	g_free (priv->ldap_search_filter);
	g_free (priv->schema_dn);

	/* Chain up to parent's finalize() method. */
	G_OBJECT_CLASS (e_book_backend_ldap_parent_class)->finalize (object);
}
book_backend_ldap_finalize (GObject *object)
{
	EBookBackendLDAPPrivate *priv;

	priv = E_BOOK_BACKEND_LDAP_GET_PRIVATE (object);

	g_rec_mutex_lock (&eds_ldap_handler_lock);
	g_rec_mutex_lock (&priv->op_hash_mutex);
	g_hash_table_foreach_remove (priv->id_to_op, (GHRFunc) call_dtor, NULL);
	g_hash_table_destroy (priv->id_to_op);
	g_rec_mutex_unlock (&priv->op_hash_mutex);
	g_rec_mutex_unlock (&eds_ldap_handler_lock);
	g_rec_mutex_clear (&priv->op_hash_mutex);
	g_mutex_clear (&priv->view_mutex);

	 
	if (priv->poll_timeout > 0) {
		g_source_remove (priv->poll_timeout);
		priv->poll_timeout = 0;
	}

	g_rec_mutex_lock (&eds_ldap_handler_lock);
	if (priv->ldap)
		ldap_unbind (priv->ldap);
	g_rec_mutex_unlock (&eds_ldap_handler_lock);

	g_slist_foreach (priv->supported_fields, (GFunc) g_free, NULL);
	g_slist_free (priv->supported_fields);

	g_slist_foreach (priv->supported_auth_methods, (GFunc) g_free, NULL);
	g_slist_free (priv->supported_auth_methods);

	g_free (priv->summary_file_name);

	if (priv->summary) {
		e_book_backend_summary_save (priv->summary);
		g_object_unref (priv->summary);
		priv->summary = NULL;
	}

	if (priv->cache) {
		g_object_unref (priv->cache);
		priv->cache = NULL;
	}

	g_free (priv->ldap_host);
	g_free (priv->ldap_rootdn);
	g_free (priv->ldap_search_filter);
	g_free (priv->schema_dn);

	 
	G_OBJECT_CLASS (e_book_backend_ldap_parent_class)->finalize (object);
}