[evolution-patches] leaks in alarm daemon (1.4)



The attached patch fixes some of the session problems in the alarm
daemon. There is still 1 leak (or maybe more) that is preventing wombat,
and b-a-s to exit when the session ends. I think this can be caused by
some leaked clients in the calendar GUI, so I'd thought to send it in a
separate patch (once I find it).

This at least makes the alarm daemon exits with the session, and fixes
the crashes on session startup (reported many times to bugzilla). So, I
guess this should go in.

cheers
Index: ChangeLog
===================================================================
RCS file: /cvs/gnome/evolution/calendar/ChangeLog,v
retrieving revision 1.1802.2.40
diff -u -p -r1.1802.2.40 ChangeLog
--- ChangeLog	5 Dec 2003 09:56:12 -0000	1.1802.2.40
+++ ChangeLog	22 Dec 2003 16:09:48 -0000
@@ -1,3 +1,20 @@
+2003-12-22  Rodrigo Moya <rodrigo ximian com>
+
+	* gui/alarm-notify/notify-main.c (client_die_cb): use
+	bonobo_main_quit, not gtk_main_quit.
+
+	* gui/alarm-notify/alarm-queue.c (free_client_alarms_cb): callback
+	for freeing ClientAlarms stored in the hash table.
+	(alarm_queue_done): call free_client_alarms_cb() for each opened
+	client.
+
+	* gui/alarm-notify/alarm-notify.c (free_client_hash): new function
+	to remove items from the CalClient's hash table.
+	(alarm_notify_finalize): call free_client_hash() for each item
+	in the hash table.
+	(alarm_notify_add_calendar): don't leak the EUri if the client is
+	already in the hash table.
+
 2003-11-24  Yong Sun <Yong Sun Sun com>
 
 	Fix for #51337
Index: gui/alarm-notify/alarm-notify.c
===================================================================
RCS file: /cvs/gnome/evolution/calendar/gui/alarm-notify/alarm-notify.c,v
retrieving revision 1.20.4.1
diff -u -p -r1.20.4.1 alarm-notify.c
--- gui/alarm-notify/alarm-notify.c	27 Aug 2003 02:36:19 -0000	1.20.4.1
+++ gui/alarm-notify/alarm-notify.c	22 Dec 2003 16:09:48 -0000
@@ -441,6 +441,8 @@ alarm_notify_add_calendar (AlarmNotify *
 	if (g_hash_table_lookup_extended (priv->uri_client_hash, str_uri, &s_ptr, &lc_ptr)) {
 		lc = lc_ptr;
 		lc->refcount++;
+
+		e_uri_free (uri);
 	} else {
 		client = cal_client_new ();
 
@@ -461,6 +463,7 @@ alarm_notify_add_calendar (AlarmNotify *
 				g_hash_table_insert (priv->uri_client_hash,
 						     g_strdup (str_uri), lc);
 			} else {
+				e_uri_free (uri);
 				g_free (lc);
 				g_object_unref (G_OBJECT (client));
 				client = NULL;
Index: gui/alarm-notify/alarm-queue.c
===================================================================
RCS file: /cvs/gnome/evolution/calendar/gui/alarm-notify/alarm-queue.c,v
retrieving revision 1.40
diff -u -p -r1.40 alarm-queue.c
--- gui/alarm-notify/alarm-queue.c	13 May 2003 22:59:06 -0000	1.40
+++ gui/alarm-notify/alarm-queue.c	22 Dec 2003 16:09:49 -0000
@@ -986,6 +986,69 @@ alarm_queue_init (void)
 	alarm_queue_inited = TRUE;
 }
 
+/* Called from g_hash_table_foreach(); adds a component UID to a list */
+static void
+add_uid_cb (gpointer key, gpointer value, gpointer data)
+{
+	GSList **uids;
+	const char *uid;
+
+	uids = data;
+	uid = key;
+
+	*uids = g_slist_prepend (*uids, (char *) uid);
+}
+
+/* Removes all the alarms queued for a particular calendar client */
+static void
+remove_client_alarms (ClientAlarms *ca)
+{
+	GSList *uids;
+	GSList *l;
+
+	/* First we build a list of UIDs so that we can remove them one by one */
+
+	uids = NULL;
+	g_hash_table_foreach (ca->uid_alarms_hash, add_uid_cb, &uids);
+
+	for (l = uids; l; l = l->next) {
+		const char *uid;
+
+		uid = l->data;
+
+		remove_comp (ca, uid);
+	}
+
+	g_slist_free (uids);
+
+	/* The hash table should be empty now */
+
+	g_assert (g_hash_table_size (ca->uid_alarms_hash) == 0);
+}
+
+static void
+free_client_alarms_cb (gpointer key, gpointer value, gpointer user_data)
+{
+	ClientAlarms *ca = value;
+
+	if (ca) {
+		remove_client_alarms (ca);
+
+		/* Clean up */
+
+		g_signal_handlers_disconnect_matched (ca->client, G_SIGNAL_MATCH_DATA,
+						      0, 0, NULL, NULL, ca);
+
+		g_object_unref (ca->client);
+		ca->client = NULL;
+
+		g_hash_table_destroy (ca->uid_alarms_hash);
+		ca->uid_alarms_hash = NULL;
+
+		g_free (ca);
+	}
+}
+
 /**
  * alarm_queue_done:
  *
@@ -1001,6 +1064,7 @@ alarm_queue_done (void)
 	/* All clients must be unregistered by now */
 	g_return_if_fail (g_hash_table_size (client_alarms_hash) == 0);
 
+	g_hash_table_foreach (client_alarms_hash, (GHFunc) free_client_alarms_cb, NULL);
 	g_hash_table_destroy (client_alarms_hash);
 	client_alarms_hash = NULL;
 
@@ -1068,46 +1132,6 @@ alarm_queue_add_client (CalClient *clien
 	}
 }
 
-/* Called from g_hash_table_foreach(); adds a component UID to a list */
-static void
-add_uid_cb (gpointer key, gpointer value, gpointer data)
-{
-	GSList **uids;
-	const char *uid;
-
-	uids = data;
-	uid = key;
-
-	*uids = g_slist_prepend (*uids, (char *) uid);
-}
-
-/* Removes all the alarms queued for a particular calendar client */
-static void
-remove_client_alarms (ClientAlarms *ca)
-{
-	GSList *uids;
-	GSList *l;
-
-	/* First we build a list of UIDs so that we can remove them one by one */
-
-	uids = NULL;
-	g_hash_table_foreach (ca->uid_alarms_hash, add_uid_cb, &uids);
-
-	for (l = uids; l; l = l->next) {
-		const char *uid;
-
-		uid = l->data;
-
-		remove_comp (ca, uid);
-	}
-
-	g_slist_free (uids);
-
-	/* The hash table should be empty now */
-
-	g_assert (g_hash_table_size (ca->uid_alarms_hash) == 0);
-}
-
 /**
  * alarm_queue_remove_client:
  * @client: A calendar client.
Index: gui/alarm-notify/notify-main.c
===================================================================
RCS file: /cvs/gnome/evolution/calendar/gui/alarm-notify/notify-main.c,v
retrieving revision 1.25.4.2
diff -u -p -r1.25.4.2 notify-main.c
--- gui/alarm-notify/notify-main.c	22 Aug 2003 15:23:35 -0000	1.25.4.2
+++ gui/alarm-notify/notify-main.c	22 Dec 2003 16:09:49 -0000
@@ -34,7 +34,6 @@
 #include <bonobo/bonobo-main.h>
 #include <bonobo/bonobo-generic-factory.h>
 #include <bonobo-activation/bonobo-activation.h>
-#include <gtk/gtkmain.h>
 #include "alarm.h"
 #include "alarm-queue.h"
 #include "alarm-notify.h"
@@ -55,7 +54,7 @@ static AlarmNotify *alarm_notify_service
 static void
 client_die_cb (GnomeClient *client)
 {
-	gtk_main_quit ();
+	bonobo_main_quit ();
 }
 
 /* Sees if a session manager is present.  If so, it tells the SM how to restart
@@ -193,11 +192,12 @@ main (int argc, char **argv)
 	bonobo_object_unref (BONOBO_OBJECT (factory));
 	factory = NULL;
 
-	/* FIXME: free the alarm_notify_service */
-
 	alarm_queue_done ();
 	alarm_done ();
 
+	if (alarm_notify_service)
+		bonobo_object_unref (BONOBO_OBJECT (alarm_notify_service));
+
 	gnome_sound_shutdown ();
 	gnome_vfs_shutdown ();
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]