[evolution-patches] Calendar, addressbook: Destroy, dispose, finalize



These patches add missing upwards chaining of destroy, dispose and
finalize calls, and fix a surprising amount of potential double frees
and unrefs, as per Ettore's findings.

I'd like to apply both to head and the 1.4 branch.

--
Hans Petter
Index: ChangeLog
===================================================================
RCS file: /cvs/gnome/evolution/addressbook/ChangeLog,v
retrieving revision 1.1442
diff -u -p -r1.1442 ChangeLog
--- ChangeLog	27 Jul 2003 22:45:11 -0000	1.1442
+++ ChangeLog	13 Aug 2003 05:01:02 -0000
@@ -1,3 +1,45 @@
+2003-08-12  Hans Petter Jansson  <hpj ximian com>
+
+	* backend/ebook/e-destination.c (e_destination_dispose): Chain.
+
+	* gui/component/e-address-widget.c (e_address_widget_destroy): Chain.
+	Prevent double frees. Prevent double GSource removal.
+
+	* gui/component/e-cardlist-model.c (e_cardlist_model_class_init):
+	Store parent class.
+	(e_cardlist_model_dispose): Chain. Prevent double frees and unrefs.
+
+	* gui/contact-editor/e-contact-editor-address.c
+	(e_contact_editor_address_dispose): Chain.
+
+	* gui/contact-editor/e-contact-editor-fullname.c
+	(e_contact_editor_fullname_dispose): Chain.
+
+	* gui/contact-list-editor/e-contact-list-editor.c
+	(e_contact_list_editor_dispose): Chain.
+
+	* gui/contact-list-editor/e-contact-list-model.c
+	(contact_list_model_destroy): Chain. Prevent double frees and unrefs.
+
+	* gui/widgets/e-addressbook-reflow-adapter.c (addressbook_dispose):
+	Chain.
+	(addressbook_finalize): Chain.
+
+	* gui/widgets/e-addressbook-table-adapter.c (addressbook_dispose):
+	Chain.
+
+	* gui/widgets/e-addressbook-treeview-adapter.c (addressbook_destroy):
+	Chain. Prevent double free.
+
+	* gui/widgets/gal-view-minicard.c (gal_view_minicard_dispose):
+	Chain. Prevent double free and detach.
+
+	* gui/widgts/gal-view-treeview.c (gal_view_treeview_dispose):
+	Chain. Prevent double free and detach.
+
+	* printins/e-contact-print-style-editor.c
+	(e_contact_print_stule_editor_destroy): Chain. Prevent double unref.
+
 2003-07-23  Chris Toshok  <toshok ximian com>
 
 	* printing/e-contact-print.c (e_contact_print_response): deal with
Index: backend/ebook/e-destination.c
===================================================================
RCS file: /cvs/gnome/evolution/addressbook/backend/ebook/e-destination.c,v
retrieving revision 1.57
diff -u -p -r1.57 e-destination.c
--- backend/ebook/e-destination.c	19 May 2003 20:26:34 -0000	1.57
+++ backend/ebook/e-destination.c	13 Aug 2003 05:01:08 -0000
@@ -110,6 +110,9 @@ e_destination_dispose (GObject *obj)
 		g_free (dest->priv);
 		dest->priv = NULL;
 	}
+
+	if (G_OBJECT_CLASS (parent_class)->dispose)
+		(* G_OBJECT_CLASS (parent_class)->dispose) (obj);
 }
 
 static void
Index: gui/component/e-address-widget.c
===================================================================
RCS file: /cvs/gnome/evolution/addressbook/gui/component/e-address-widget.c,v
retrieving revision 1.14
diff -u -p -r1.14 e-address-widget.c
--- gui/component/e-address-widget.c	5 Feb 2003 23:48:52 -0000	1.14
+++ gui/component/e-address-widget.c	13 Aug 2003 05:01:09 -0000
@@ -74,13 +74,22 @@ e_address_widget_destroy (GtkObject *obj
 	EAddressWidget *addr = E_ADDRESS_WIDGET (obj);
 
 	g_free (addr->name);
+	addr->name = NULL;
+
 	g_free (addr->email);
+	addr->email = NULL;
 
-	if (addr->query_tag)
+	if (addr->query_tag) {
 		e_book_simple_query_cancel (common_book, addr->query_tag);
+		addr->query_tag = 0;
+	}
 
-	if (addr->query_idle_tag)
+	if (addr->query_idle_tag) {
 		g_source_remove (addr->query_idle_tag);
+		addr->query_idle_tag = 0;
+	}
+
+	(* GTK_OBJECT_CLASS (parent_class)->destroy) (obj);
 }
 
 static gint
Index: gui/component/e-cardlist-model.c
===================================================================
RCS file: /cvs/gnome/evolution/addressbook/gui/component/e-cardlist-model.c,v
retrieving revision 1.13
diff -u -p -r1.13 e-cardlist-model.c
--- gui/component/e-cardlist-model.c	14 Jun 2003 04:34:07 -0000	1.13
+++ gui/component/e-cardlist-model.c	13 Aug 2003 05:01:09 -0000
@@ -18,16 +18,24 @@
 
 #define PARENT_TYPE e_table_model_get_type()
 
+static GObjectClass *parent_class = NULL;
+
 static void
 e_cardlist_model_dispose(GObject *object)
 {
 	ECardlistModel *model = E_CARDLIST_MODEL(object);
 	int i;
 
-	for ( i = 0; i < model->data_count; i++ ) {
-		g_object_unref(model->data[i]);
+	if (model->data != NULL) {
+		for ( i = 0; i < model->data_count; i++ ) {
+			g_object_unref(model->data[i]);
+		}
+		g_free(model->data);
+		model->data = NULL;
 	}
-	g_free(model->data);
+
+	if (G_OBJECT_CLASS (parent_class)->dispose)
+		(* G_OBJECT_CLASS (parent_class)->dispose) (object);
 }
 
 /* This function returns the number of columns in our ETableModel. */
@@ -157,6 +165,8 @@ static void
 e_cardlist_model_class_init (GObjectClass *object_class)
 {
 	ETableModelClass *model_class = (ETableModelClass *) object_class;
+
+	parent_class = g_type_class_peek_parent (object_class);
 	
 	object_class->dispose = e_cardlist_model_dispose;
 
Index: gui/contact-editor/e-contact-editor-address.c
===================================================================
RCS file: /cvs/gnome/evolution/addressbook/gui/contact-editor/e-contact-editor-address.c,v
retrieving revision 1.25
diff -u -p -r1.25 e-contact-editor-address.c
--- gui/contact-editor/e-contact-editor-address.c	27 Feb 2003 23:06:58 -0000	1.25
+++ gui/contact-editor/e-contact-editor-address.c	13 Aug 2003 05:01:29 -0000
@@ -457,6 +457,9 @@ e_contact_editor_address_dispose (GObjec
 		e_card_delivery_address_unref(e_contact_editor_address->address);
 		e_contact_editor_address->address = NULL;
 	}
+
+	if (G_OBJECT_CLASS (parent_class)->dispose)
+		(* G_OBJECT_CLASS (parent_class)->dispose) (object);
 }
 
 GtkWidget*
Index: gui/contact-editor/e-contact-editor-fullname.c
===================================================================
RCS file: /cvs/gnome/evolution/addressbook/gui/contact-editor/e-contact-editor-fullname.c,v
retrieving revision 1.23
diff -u -p -r1.23 e-contact-editor-fullname.c
--- gui/contact-editor/e-contact-editor-fullname.c	27 Feb 2003 23:06:58 -0000	1.23
+++ gui/contact-editor/e-contact-editor-fullname.c	13 Aug 2003 05:01:34 -0000
@@ -145,6 +145,9 @@ e_contact_editor_fullname_dispose (GObje
 		e_card_name_unref(e_contact_editor_fullname->name);
 		e_contact_editor_fullname->name = NULL;
 	}
+
+	if (G_OBJECT_CLASS (parent_class)->dispose)
+		(* G_OBJECT_CLASS (parent_class)->dispose) (object);
 }
 
 GtkWidget*
Index: gui/contact-list-editor/e-contact-list-editor.c
===================================================================
RCS file: /cvs/gnome/evolution/addressbook/gui/contact-list-editor/e-contact-list-editor.c,v
retrieving revision 1.43
diff -u -p -r1.43 e-contact-list-editor.c
--- gui/contact-list-editor/e-contact-list-editor.c	23 Jul 2003 16:41:54 -0000	1.43
+++ gui/contact-list-editor/e-contact-list-editor.c	13 Aug 2003 05:01:39 -0000
@@ -311,7 +311,8 @@ e_contact_list_editor_init (EContactList
 static void
 e_contact_list_editor_dispose (GObject *object)
 {
-	/* XXX need to call parent dispose */
+	if (G_OBJECT_CLASS (parent_class)->dispose)
+		(* G_OBJECT_CLASS (parent_class)->dispose) (object);
 }
 
 typedef struct {
Index: gui/contact-list-editor/e-contact-list-model.c
===================================================================
RCS file: /cvs/gnome/evolution/addressbook/gui/contact-list-editor/e-contact-list-model.c,v
retrieving revision 1.14
diff -u -p -r1.14 e-contact-list-model.c
--- gui/contact-list-editor/e-contact-list-model.c	6 May 2003 19:20:31 -0000	1.14
+++ gui/contact-list-editor/e-contact-list-model.c	13 Aug 2003 05:01:39 -0000
@@ -85,13 +85,18 @@ contact_list_model_destroy (GtkObject *o
 	EContactListModel *model = E_CONTACT_LIST_MODEL (o);
 	int i;
 
-	for (i = 0; i < model->data_count; i ++) {
-		g_object_unref (model->data[i]);
+	if (model->data != NULL) {
+		for (i = 0; i < model->data_count; i ++) {
+			g_object_unref (model->data[i]);
+		}
+		g_free (model->data);
+		model->data = NULL;
 	}
-	g_free (model->data);
 
 	model->data_count = 0;
 	model->data_alloc = 0;
+
+	(* GTK_OBJECT_CLASS (parent_class)->destroy) (o);
 }
 
 static void
Index: gui/widgets/e-addressbook-reflow-adapter.c
===================================================================
RCS file: /cvs/gnome/evolution/addressbook/gui/widgets/e-addressbook-reflow-adapter.c,v
retrieving revision 1.28
diff -u -p -r1.28 e-addressbook-reflow-adapter.c
--- gui/widgets/e-addressbook-reflow-adapter.c	17 Jul 2003 16:54:51 -0000	1.28
+++ gui/widgets/e-addressbook-reflow-adapter.c	13 Aug 2003 05:01:39 -0000
@@ -104,6 +104,9 @@ addressbook_dispose(GObject *object)
 	EAddressbookReflowAdapter *adapter = E_ADDRESSBOOK_REFLOW_ADAPTER(object);
 
 	unlink_model (adapter);
+
+	if (G_OBJECT_CLASS (parent_class)->dispose)
+		(* G_OBJECT_CLASS (parent_class)->dispose) (object);
 }
 
 static void
@@ -112,6 +115,9 @@ addressbook_finalize(GObject *object)
 	EAddressbookReflowAdapter *adapter = E_ADDRESSBOOK_REFLOW_ADAPTER(object);
 
 	g_free (adapter->priv);
+
+	if (G_OBJECT_CLASS (parent_class)->finalize)
+		(* G_OBJECT_CLASS (parent_class)->finalize) (object);
 }
 
 static void
Index: gui/widgets/e-addressbook-table-adapter.c
===================================================================
RCS file: /cvs/gnome/evolution/addressbook/gui/widgets/e-addressbook-table-adapter.c,v
retrieving revision 1.25
diff -u -p -r1.25 e-addressbook-table-adapter.c
--- gui/widgets/e-addressbook-table-adapter.c	14 Jun 2003 04:34:19 -0000	1.25
+++ gui/widgets/e-addressbook-table-adapter.c	13 Aug 2003 05:01:44 -0000
@@ -91,6 +91,9 @@ addressbook_dispose(GObject *object)
 		g_free (adapter->priv);
 		adapter->priv = NULL;
 	}
+
+	if (G_OBJECT_CLASS (parent_class)->dispose)
+		(* G_OBJECT_CLASS (parent_class)->dispose) (object);
 }
 
 /* This function returns the number of columns in our ETableModel. */
Index: gui/widgets/e-addressbook-treeview-adapter.c
===================================================================
RCS file: /cvs/gnome/evolution/addressbook/gui/widgets/e-addressbook-treeview-adapter.c,v
retrieving revision 1.2
diff -u -p -r1.2 e-addressbook-treeview-adapter.c
--- gui/widgets/e-addressbook-treeview-adapter.c	23 Mar 2003 09:18:03 -0000	1.2
+++ gui/widgets/e-addressbook-treeview-adapter.c	13 Aug 2003 05:01:47 -0000
@@ -89,6 +89,9 @@ addressbook_destroy(GtkObject *object)
 	unlink_model(adapter);
 
 	g_free (adapter->priv);
+	adapter->priv = NULL;
+
+	(* GTK_OBJECT_CLASS (parent_class)->destroy) (object);
 }
 
 #if 0
Index: gui/widgets/gal-view-minicard.c
===================================================================
RCS file: /cvs/gnome/evolution/addressbook/gui/widgets/gal-view-minicard.c,v
retrieving revision 1.11
diff -u -p -r1.11 gal-view-minicard.c
--- gui/widgets/gal-view-minicard.c	6 Mar 2003 17:30:51 -0000	1.11
+++ gui/widgets/gal-view-minicard.c	13 Aug 2003 05:01:50 -0000
@@ -89,8 +89,15 @@ static void
 gal_view_minicard_dispose         (GObject *object)
 {
 	GalViewMinicard *view = GAL_VIEW_MINICARD(object);
-	gal_view_minicard_detach (view);
-	g_free(view->title);
+
+	if (view->title != NULL) {
+		gal_view_minicard_detach (view);
+		g_free(view->title);
+		view->title = NULL;
+	}
+
+	if (G_OBJECT_CLASS (gal_view_minicard_parent_class)->dispose)
+		(* G_OBJECT_CLASS (gal_view_minicard_parent_class)->dispose) (object);
 }
 
 static void
Index: gui/widgets/gal-view-treeview.c
===================================================================
RCS file: /cvs/gnome/evolution/addressbook/gui/widgets/gal-view-treeview.c,v
retrieving revision 1.2
diff -u -p -r1.2 gal-view-treeview.c
--- gui/widgets/gal-view-treeview.c	6 Mar 2003 17:30:51 -0000	1.2
+++ gui/widgets/gal-view-treeview.c	13 Aug 2003 05:01:50 -0000
@@ -92,8 +92,15 @@ static void
 gal_view_treeview_dispose         (GObject *object)
 {
 	GalViewTreeView *view = GAL_VIEW_TREEVIEW(object);
-	gal_view_treeview_detach (view);
-	g_free(view->title);
+
+	if (view->title != NULL) {
+		gal_view_treeview_detach (view);
+		g_free(view->title);
+		view->title = NULL;
+	}
+
+	if (G_OBJECT_CLASS (gal_view_treeview_parent_class)->dispose)
+		(* G_OBJECT_CLASS (gal_view_treeview_parent_class)->dispose) (object);
 }
 
 static void
Index: printing/e-contact-print-style-editor.c
===================================================================
RCS file: /cvs/gnome/evolution/addressbook/printing/e-contact-print-style-editor.c,v
retrieving revision 1.6
diff -u -p -r1.6 e-contact-print-style-editor.c
--- printing/e-contact-print-style-editor.c	7 Nov 2002 07:38:30 -0000	1.6
+++ printing/e-contact-print-style-editor.c	13 Aug 2003 05:01:50 -0000
@@ -111,7 +111,13 @@ void
 e_contact_print_style_editor_destroy (GtkObject *object)
 {
 	EContactPrintStyleEditor *e_contact_print_style_editor = E_CONTACT_PRINT_STYLE_EDITOR(object);
-	g_object_unref(e_contact_print_style_editor->gui);
+
+	if (e_contact_print_style_editor->gui != NULL) {
+		g_object_unref(e_contact_print_style_editor->gui);
+		e_contact_print_style_editor->gui = NULL;
+	}
+
+	(* GTK_OBJECT_CLASS (parent_class)->destroy) (object);
 }
 
 GtkWidget*
? evolution-calendar-itip-destroy-chain.patch
? gui/dispose
Index: ChangeLog
===================================================================
RCS file: /cvs/gnome/evolution/calendar/ChangeLog,v
retrieving revision 1.1850
diff -u -p -r1.1850 ChangeLog
--- ChangeLog	13 Aug 2003 01:49:53 -0000	1.1850
+++ ChangeLog	13 Aug 2003 05:01:21 -0000
@@ -1,3 +1,20 @@
+2003-08-12  Hans Petter Jansson  <hpj ximian com>
+
+	* gui/calendar-offline-handler.c (impl_dispose): Chain. Prevent
+	double unrefs.
+	(impl_finalize): Chain.
+
+	* gui/e-alarm-list.c (finalize): Chain.
+
+	* gui/e-comp-editor-registry.c (destroy): Chain. Prevent double frees.
+	(editor_destroy_cb): Don't crash if we get the destroy signal twice.
+
+	* gui/e-date-time-list.c (e_date_time_list_finalize): Chain.
+
+	* gui/e-meeting-attendee.c (finalize): Chain.
+
+	* gui/e-meeting-model.c (finalize): Chain.
+
 2003-08-12 Andrew Wu <Yang Wu sun com>
 
        * gui/e-day-view.c
Index: gui/calendar-offline-handler.c
===================================================================
RCS file: /cvs/gnome/evolution/calendar/gui/calendar-offline-handler.c,v
retrieving revision 1.13
diff -u -p -r1.13 calendar-offline-handler.c
--- gui/calendar-offline-handler.c	14 May 2003 18:45:55 -0000	1.13
+++ gui/calendar-offline-handler.c	13 Aug 2003 05:01:21 -0000
@@ -258,7 +258,10 @@ impl_dispose (GObject *object)
 	offline_handler = CALENDAR_OFFLINE_HANDLER (object);
 	priv = offline_handler->priv;
 
-	g_object_unref (priv->client);
+	if (priv->client) {
+		g_object_unref (priv->client);
+		priv->client = NULL;
+	}
 	
 	if (priv->listener_interface != CORBA_OBJECT_NIL) {
 		CORBA_Environment ev;
@@ -270,6 +273,8 @@ impl_dispose (GObject *object)
 		priv->listener_interface = CORBA_OBJECT_NIL;
 	}
 
+	if (G_OBJECT_CLASS (parent_class)->dispose)
+		(* G_OBJECT_CLASS (parent_class)->dispose) (object);
 }
 
 static void
@@ -282,6 +287,9 @@ impl_finalize (GObject *object)
 	priv = offline_handler->priv;
 
 	g_free (priv);
+
+	if (G_OBJECT_CLASS (parent_class)->finalize)
+		(* G_OBJECT_CLASS (parent_class)->finalize) (object);
 }
 
 /* GTK+ type initialization.  */
Index: gui/e-alarm-list.c
===================================================================
RCS file: /cvs/gnome/evolution/calendar/gui/e-alarm-list.c,v
retrieving revision 1.3
diff -u -p -r1.3 e-alarm-list.c
--- gui/e-alarm-list.c	1 Aug 2003 10:54:21 -0000	1.3
+++ gui/e-alarm-list.c	13 Aug 2003 05:01:21 -0000
@@ -225,6 +225,9 @@ static void
 e_alarm_list_finalize (GObject *object)
 {
 	EAlarmList *alarm_list = E_ALARM_LIST (object);
+
+	if (G_OBJECT_CLASS (parent_class)->finalize)
+		(* G_OBJECT_CLASS (parent_class)->finalize) (object);
 }
 
 /* Fulfill the GtkTreeModel requirements */
Index: gui/e-comp-editor-registry.c
===================================================================
RCS file: /cvs/gnome/evolution/calendar/gui/e-comp-editor-registry.c,v
retrieving revision 1.7
diff -u -p -r1.7 e-comp-editor-registry.c
--- gui/e-comp-editor-registry.c	19 Dec 2002 13:09:10 -0000	1.7
+++ gui/e-comp-editor-registry.c	13 Aug 2003 05:01:21 -0000
@@ -50,13 +50,21 @@ destroy (GtkObject *obj)
 {
 	ECompEditorRegistry *reg;
 	ECompEditorRegistryPrivate *priv;
-	
+
 	reg = E_COMP_EDITOR_REGISTRY (obj);
 	priv = reg->priv;
 
-	g_hash_table_destroy (priv->editors);
-	
-	g_free (priv);
+	if (priv) {
+		if (priv->editors) {
+			g_hash_table_destroy (priv->editors);
+			priv->editors = NULL;
+		}
+
+		g_free (priv);
+		reg->priv = NULL;
+	}
+
+	(* GTK_OBJECT_CLASS (parent_class)->destroy) (obj);
 }
 
 static void
@@ -195,10 +203,10 @@ editor_destroy_cb (GtkWidget *widget, gp
 	cal_component_get_uid (comp, &uid);
 
 	rdata = g_hash_table_lookup (priv->editors, uid);
-	g_assert (rdata != NULL);
-	
-	g_hash_table_remove (priv->editors, rdata->uid);
-	g_free (rdata->uid);
-	g_free (rdata);
-}
 
+	if (rdata != NULL) {
+		g_hash_table_remove (priv->editors, rdata->uid);
+		g_free (rdata->uid);
+		g_free (rdata);
+	}
+}
Index: gui/e-date-time-list.c
===================================================================
RCS file: /cvs/gnome/evolution/calendar/gui/e-date-time-list.c,v
retrieving revision 1.3
diff -u -p -r1.3 e-date-time-list.c
--- gui/e-date-time-list.c	1 Jan 1997 09:59:15 -0000	1.3
+++ gui/e-date-time-list.c	13 Aug 2003 05:01:21 -0000
@@ -223,6 +223,9 @@ static void
 e_date_time_list_finalize (GObject *object)
 {
 	EDateTimeList *date_time_list = E_DATE_TIME_LIST (object);
+
+	if (G_OBJECT_CLASS (parent_class)->finalize)
+		(* G_OBJECT_CLASS (parent_class)->finalize) (object);
 }
 
 /* Fulfill the GtkTreeModel requirements */
Index: gui/e-meeting-attendee.c
===================================================================
RCS file: /cvs/gnome/evolution/calendar/gui/e-meeting-attendee.c,v
retrieving revision 1.9
diff -u -p -r1.9 e-meeting-attendee.c
--- gui/e-meeting-attendee.c	7 Apr 2003 07:13:20 -0000	1.9
+++ gui/e-meeting-attendee.c	13 Aug 2003 05:01:22 -0000
@@ -187,6 +187,9 @@ finalize (GObject *obj)
 	g_array_free (priv->busy_periods, TRUE);
 	
 	g_free (priv);
+
+	if (G_OBJECT_CLASS (parent_class)->finalize)
+		(* G_OBJECT_CLASS (parent_class)->finalize) (obj);
 }
 
 GObject *
Index: gui/e-meeting-model.c
===================================================================
RCS file: /cvs/gnome/evolution/calendar/gui/e-meeting-model.c,v
retrieving revision 1.48
diff -u -p -r1.48 e-meeting-model.c
--- gui/e-meeting-model.c	2 May 2003 12:37:15 -0000	1.48
+++ gui/e-meeting-model.c	13 Aug 2003 05:01:35 -0000
@@ -671,6 +671,9 @@ finalize (GObject *obj)
  		g_source_remove (priv->refresh_idle_id);
  		
 	g_free (priv);
+
+	if (G_OBJECT_CLASS (parent_class)->finalize)
+ 		(* G_OBJECT_CLASS (parent_class)->finalize) (obj);
 }
 
 GtkObject *


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