views: Instrument and fix reference leaks

parent 58b33407
...@@ -157,6 +157,8 @@ destroy_event_cache_map (void) ...@@ -157,6 +157,8 @@ destroy_event_cache_map (void)
{ {
GList *events; GList *events;
g_debug ("Number of cached events at destruction: %d", g_hash_table_size (event_cache));
/* Destroy all events */ /* Destroy all events */
events = g_hash_table_get_values (event_cache); events = g_hash_table_get_values (event_cache);
g_list_free_full (events, g_object_unref); g_list_free_full (events, g_object_unref);
......
...@@ -1357,11 +1357,13 @@ gcal_month_view_component_added (ECalDataModelSubscriber *subscriber, ...@@ -1357,11 +1357,13 @@ gcal_month_view_component_added (ECalDataModelSubscriber *subscriber,
ECalClient *client, ECalClient *client,
ECalComponent *comp) ECalComponent *comp)
{ {
g_autoptr (GcalEvent) event = NULL;
GcalMonthView *self; GcalMonthView *self;
GtkWidget *event_widget; GtkWidget *event_widget;
GcalEvent *event;
GError *error; GError *error;
GCAL_ENTRY;
error = NULL; error = NULL;
self = GCAL_MONTH_VIEW (subscriber); self = GCAL_MONTH_VIEW (subscriber);
event = gcal_event_new (e_client_get_source (E_CLIENT (client)), comp, &error); event = gcal_event_new (e_client_get_source (E_CLIENT (client)), comp, &error);
...@@ -1370,7 +1372,7 @@ gcal_month_view_component_added (ECalDataModelSubscriber *subscriber, ...@@ -1370,7 +1372,7 @@ gcal_month_view_component_added (ECalDataModelSubscriber *subscriber,
{ {
g_warning ("Error creating event: %s", error->message); g_warning ("Error creating event: %s", error->message);
g_clear_error (&error); g_clear_error (&error);
return; GCAL_RETURN ();
} }
event_widget = gcal_event_widget_new (event); event_widget = gcal_event_widget_new (event);
...@@ -1381,7 +1383,7 @@ gcal_month_view_component_added (ECalDataModelSubscriber *subscriber, ...@@ -1381,7 +1383,7 @@ gcal_month_view_component_added (ECalDataModelSubscriber *subscriber,
self->pending_event_allocation = TRUE; self->pending_event_allocation = TRUE;
g_clear_object (&event); GCAL_EXIT;
} }
static void static void
...@@ -1389,12 +1391,14 @@ gcal_month_view_component_modified (ECalDataModelSubscriber *subscriber, ...@@ -1389,12 +1391,14 @@ gcal_month_view_component_modified (ECalDataModelSubscriber *subscriber,
ECalClient *client, ECalClient *client,
ECalComponent *comp) ECalComponent *comp)
{ {
g_autoptr (GcalEvent) event = NULL;
GcalMonthView *self; GcalMonthView *self;
GtkWidget *new_widget; GtkWidget *new_widget;
GcalEvent *event;
GError *error; GError *error;
GList *l; GList *l;
GCAL_ENTRY;
error = NULL; error = NULL;
self = GCAL_MONTH_VIEW (subscriber); self = GCAL_MONTH_VIEW (subscriber);
event = gcal_event_new (e_client_get_source (E_CLIENT (client)), comp, &error); event = gcal_event_new (e_client_get_source (E_CLIENT (client)), comp, &error);
...@@ -1403,7 +1407,7 @@ gcal_month_view_component_modified (ECalDataModelSubscriber *subscriber, ...@@ -1403,7 +1407,7 @@ gcal_month_view_component_modified (ECalDataModelSubscriber *subscriber,
{ {
g_warning ("Error creating event: %s", error->message); g_warning ("Error creating event: %s", error->message);
g_clear_error (&error); g_clear_error (&error);
return; GCAL_RETURN ();
} }
new_widget = gcal_event_widget_new (event); new_widget = gcal_event_widget_new (event);
...@@ -1427,7 +1431,7 @@ gcal_month_view_component_modified (ECalDataModelSubscriber *subscriber, ...@@ -1427,7 +1431,7 @@ gcal_month_view_component_modified (ECalDataModelSubscriber *subscriber,
self->pending_event_allocation = TRUE; self->pending_event_allocation = TRUE;
g_clear_object (&event); GCAL_EXIT;
} }
static void static void
...@@ -1441,6 +1445,8 @@ gcal_month_view_component_removed (ECalDataModelSubscriber *subscriber, ...@@ -1441,6 +1445,8 @@ gcal_month_view_component_removed (ECalDataModelSubscriber *subscriber,
const gchar *sid; const gchar *sid;
GList *l; GList *l;
GCAL_ENTRY;
self = GCAL_MONTH_VIEW (subscriber); self = GCAL_MONTH_VIEW (subscriber);
sid = e_source_get_uid (e_client_get_source (E_CLIENT (client))); sid = e_source_get_uid (e_client_get_source (E_CLIENT (client)));
...@@ -1457,12 +1463,14 @@ gcal_month_view_component_removed (ECalDataModelSubscriber *subscriber, ...@@ -1457,12 +1463,14 @@ gcal_month_view_component_removed (ECalDataModelSubscriber *subscriber,
G_STRFUNC, G_STRFUNC,
uuid, uuid,
gtk_widget_get_name (GTK_WIDGET (subscriber))); gtk_widget_get_name (GTK_WIDGET (subscriber)));
return; GCAL_RETURN ();
} }
gtk_widget_destroy (l->data); gtk_widget_destroy (l->data);
self->pending_event_allocation = TRUE; self->pending_event_allocation = TRUE;
GCAL_EXIT;
} }
static void static void
......
...@@ -1153,6 +1153,8 @@ gcal_week_grid_add_event (GcalWeekGrid *self, ...@@ -1153,6 +1153,8 @@ gcal_week_grid_add_event (GcalWeekGrid *self,
end = 0; end = 0;
start = 0; start = 0;
g_object_ref (event);
widget = g_object_new (GCAL_TYPE_EVENT_WIDGET, widget = g_object_new (GCAL_TYPE_EVENT_WIDGET,
"event", event, "event", event,
"orientation", GTK_ORIENTATION_VERTICAL, "orientation", GTK_ORIENTATION_VERTICAL,
...@@ -1200,6 +1202,7 @@ gcal_week_grid_remove_event (GcalWeekGrid *self, ...@@ -1200,6 +1202,7 @@ gcal_week_grid_remove_event (GcalWeekGrid *self,
gcal_range_tree_remove_range (self->events, data->start, data->end, data); gcal_range_tree_remove_range (self->events, data->start, data->end, data);
destroy_event_widget (self, data->widget); destroy_event_widget (self, data->widget);
gtk_widget_queue_allocate (GTK_WIDGET (self)); gtk_widget_queue_allocate (GTK_WIDGET (self));
g_object_unref (event);
g_free (data); g_free (data);
} }
......
...@@ -723,6 +723,9 @@ add_event_to_grid (GcalWeekHeader *self, ...@@ -723,6 +723,9 @@ add_event_to_grid (GcalWeekHeader *self,
gint position; gint position;
gint i; gint i;
/* Take a reference to the event */
g_object_ref (event);
/* Add at least at the first weekday */ /* Add at least at the first weekday */
position = add_event_to_weekday (self, event, start); position = add_event_to_weekday (self, event, start);
...@@ -1909,7 +1912,7 @@ void ...@@ -1909,7 +1912,7 @@ void
gcal_week_header_remove_event (GcalWeekHeader *self, gcal_week_header_remove_event (GcalWeekHeader *self,
const gchar *uuid) const gchar *uuid)
{ {
GcalEvent *removed_event; g_autoptr (GcalEvent) removed_event = NULL;
GList *children, *l; GList *children, *l;
gint weekday; gint weekday;
......
...@@ -304,8 +304,7 @@ gcal_week_view_component_added (ECalDataModelSubscriber *subscriber, ...@@ -304,8 +304,7 @@ gcal_week_view_component_added (ECalDataModelSubscriber *subscriber,
ECalComponent *comp) ECalComponent *comp)
{ {
GcalWeekView *self = GCAL_WEEK_VIEW (subscriber); GcalWeekView *self = GCAL_WEEK_VIEW (subscriber);
g_autoptr (GcalEvent) event = NULL;
GcalEvent *event;
GCAL_ENTRY; GCAL_ENTRY;
......
...@@ -1800,22 +1800,27 @@ gcal_year_view_component_added (ECalDataModelSubscriber *subscriber, ...@@ -1800,22 +1800,27 @@ gcal_year_view_component_added (ECalDataModelSubscriber *subscriber,
ECalClient *client, ECalClient *client,
ECalComponent *comp) ECalComponent *comp)
{ {
GcalYearView *self = GCAL_YEAR_VIEW (subscriber); g_autoptr (GcalEvent) event = NULL;
GcalYearView *self;
GDateTime *event_start, *event_end; GDateTime *event_start, *event_end;
GcalEvent *event;
GError *error; GError *error;
guint i, start_month, end_month; guint i, start_month, end_month;
GCAL_ENTRY;
error = NULL; error = NULL;
self = GCAL_YEAR_VIEW (subscriber);
event = gcal_event_new (e_client_get_source (E_CLIENT (client)), comp, &error); event = gcal_event_new (e_client_get_source (E_CLIENT (client)), comp, &error);
if (error) if (error)
{ {
g_warning ("Error creating event: %s", error->message); g_warning ("Error creating event: %s", error->message);
g_clear_error (&error); g_clear_error (&error);
return; GCAL_RETURN ();
} }
g_debug ("Caching event '%s' in Year view", gcal_event_get_uid (event));
event_start = gcal_event_get_date_start (event); event_start = gcal_event_get_date_start (event);
event_end = gcal_event_get_date_end (event); event_end = gcal_event_get_date_end (event);
...@@ -1836,6 +1841,8 @@ gcal_year_view_component_added (ECalDataModelSubscriber *subscriber, ...@@ -1836,6 +1841,8 @@ gcal_year_view_component_added (ECalDataModelSubscriber *subscriber,
update_sidebar (self); update_sidebar (self);
gtk_widget_queue_draw (GTK_WIDGET (self->navigator)); gtk_widget_queue_draw (GTK_WIDGET (self->navigator));
GCAL_EXIT;
} }
static void static void
...@@ -1844,13 +1851,16 @@ gcal_year_view_component_removed (ECalDataModelSubscriber *subscriber, ...@@ -1844,13 +1851,16 @@ gcal_year_view_component_removed (ECalDataModelSubscriber *subscriber,
const gchar *uid, const gchar *uid,
const gchar *rid) const gchar *rid)
{ {
GcalYearView *year_view = GCAL_YEAR_VIEW (subscriber); GcalYearView *year_view;
GList *children, *l; GList *children, *l;
ESource *source; ESource *source;
gchar *uuid; g_autofree gchar *uuid = NULL;
guint i; guint i;
gint number_of_children; gint number_of_children;
GCAL_ENTRY;
year_view = GCAL_YEAR_VIEW (subscriber);
source = e_client_get_source (E_CLIENT (client)); source = e_client_get_source (E_CLIENT (client));
if (rid != NULL) if (rid != NULL)
uuid = g_strdup_printf ("%s:%s:%s", e_source_get_uid (source), uid, rid); uuid = g_strdup_printf ("%s:%s:%s", e_source_get_uid (source), uid, rid);
...@@ -1899,9 +1909,10 @@ gcal_year_view_component_removed (ECalDataModelSubscriber *subscriber, ...@@ -1899,9 +1909,10 @@ gcal_year_view_component_removed (ECalDataModelSubscriber *subscriber,
event = g_ptr_array_index (events, j); event = g_ptr_array_index (events, j);
if (g_strcmp0 (gcal_event_get_uid (event), uuid) != 0) if (!g_str_equal (gcal_event_get_uid (event), uuid))
continue; continue;
g_debug ("Removing event '%s' from Year view's cache", uuid);
g_ptr_array_remove (events, event); g_ptr_array_remove (events, event);
} }
} }
...@@ -1909,7 +1920,8 @@ gcal_year_view_component_removed (ECalDataModelSubscriber *subscriber, ...@@ -1909,7 +1920,8 @@ gcal_year_view_component_removed (ECalDataModelSubscriber *subscriber,
gtk_widget_queue_draw (GTK_WIDGET (year_view->navigator)); gtk_widget_queue_draw (GTK_WIDGET (year_view->navigator));
g_list_free (children); g_list_free (children);
g_free (uuid);
GCAL_EXIT;
} }
static void static void
...@@ -1919,12 +1931,16 @@ gcal_year_view_component_changed (ECalDataModelSubscriber *subscriber, ...@@ -1919,12 +1931,16 @@ gcal_year_view_component_changed (ECalDataModelSubscriber *subscriber,
{ {
ECalComponentId *id; ECalComponentId *id;
GCAL_ENTRY;
id = e_cal_component_get_id (comp); id = e_cal_component_get_id (comp);
gcal_year_view_component_removed (subscriber, client, id->uid, id->rid); gcal_year_view_component_removed (subscriber, client, id->uid, id->rid);
gcal_year_view_component_added (subscriber, client, comp); gcal_year_view_component_added (subscriber, client, comp);
g_clear_pointer (&id, e_cal_component_free_id); g_clear_pointer (&id, e_cal_component_free_id);
GCAL_EXIT;
} }
static void static void
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment