views: Instrument and fix reference leaks

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