[gnome-calendar] event: fix various reference ownership issues
- From: Georges Basile Stavracas Neto <gbsneto src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-calendar] event: fix various reference ownership issues
- Date: Sat, 9 Sep 2017 01:25:42 +0000 (UTC)
commit 5a0a3fcd9c844a9d98ecf562d82066d6dae6bfec
Author: Georges Basile Stavracas Neto <georges stavracas gmail com>
Date: Fri Sep 8 22:25:18 2017 -0300
event: fix various reference ownership issues
src/gcal-event.c | 8 +++++++-
src/gcal-utils.h | 1 +
src/gcal-window.c | 24 ++++++------------------
src/views/gcal-year-view.c | 4 ++--
4 files changed, 16 insertions(+), 21 deletions(-)
---
diff --git a/src/gcal-event.c b/src/gcal-event.c
index 38cd464..e3dd041 100644
--- a/src/gcal-event.c
+++ b/src/gcal-event.c
@@ -147,7 +147,7 @@ G_DEFINE_CONSTRUCTOR (init_event_cache_map);
static void
init_event_cache_map (void)
{
- event_cache = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, g_object_unref);
+ event_cache = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, NULL);
}
G_DEFINE_DESTRUCTOR (destroy_event_cache_map);
@@ -155,6 +155,12 @@ G_DEFINE_DESTRUCTOR (destroy_event_cache_map);
static void
destroy_event_cache_map (void)
{
+ GList *events;
+
+ /* Destroy all events */
+ events = g_hash_table_get_values (event_cache);
+ g_list_free_full (events, g_object_unref);
+
g_hash_table_destroy (event_cache);
}
diff --git a/src/gcal-utils.h b/src/gcal-utils.h
index 4499e32..94ab46e 100644
--- a/src/gcal-utils.h
+++ b/src/gcal-utils.h
@@ -32,6 +32,7 @@
#define MAX_MINUTES (7 * MINUTES_PER_DAY)
#define gcal_clear_datetime(dt) g_clear_pointer (dt, g_date_time_unref)
+#define gcal_clear_timeout(pp) { if (pp && *pp) { g_source_remove (*pp); *pp = 0; } }
/**
* GcalWindowViewType:
diff --git a/src/gcal-window.c b/src/gcal-window.c
index 0802a62..18253b1 100644
--- a/src/gcal-window.c
+++ b/src/gcal-window.c
@@ -1283,23 +1283,11 @@ gcal_window_finalize (GObject *object)
GCAL_ENTRY;
- if (window->save_geometry_timeout_id > 0)
- {
- g_source_remove (window->save_geometry_timeout_id);
- window->save_geometry_timeout_id = 0;
- }
+ g_critical ("Finalizing");
- if (window->open_edit_dialog_timeout_id > 0)
- {
- g_source_remove (window->open_edit_dialog_timeout_id);
- window->open_edit_dialog_timeout_id = 0;
- }
-
- if (window->refresh_timeout_id > 0)
- {
- g_source_remove (window->refresh_timeout_id);
- window->refresh_timeout_id = 0;
- }
+ gcal_clear_timeout (&window->save_geometry_timeout_id);
+ gcal_clear_timeout (&window->open_edit_dialog_timeout_id);
+ gcal_clear_timeout (&window->refresh_timeout_id);
/* If we have a queued event to delete, remove it now */
if (window->event_to_delete)
@@ -1308,7 +1296,7 @@ gcal_window_finalize (GObject *object)
g_clear_object (&window->event_to_delete);
}
- if (window->event_creation_data != NULL)
+ if (window->event_creation_data)
{
g_clear_pointer (&window->event_creation_data->start_date, g_date_time_unref);
g_clear_pointer (&window->event_creation_data->end_date, g_date_time_unref);
@@ -1318,7 +1306,7 @@ gcal_window_finalize (GObject *object)
g_clear_object (&window->manager);
g_clear_object (&window->views_switcher);
- g_free (window->active_date);
+ g_clear_pointer (&window->active_date, g_free);
G_OBJECT_CLASS (gcal_window_parent_class)->finalize (object);
diff --git a/src/views/gcal-year-view.c b/src/views/gcal-year-view.c
index 63cf9f0..b0e786e 100644
--- a/src/views/gcal-year-view.c
+++ b/src/views/gcal-year-view.c
@@ -1842,7 +1842,7 @@ gcal_year_view_component_added (ECalDataModelSubscriber *subscriber,
/* Add the event to the cache */
for (i = start_month; i <= end_month; i++)
- g_ptr_array_add (self->events[i], event);
+ g_ptr_array_add (self->events[i], g_object_ref (event));
update_sidebar (self);
@@ -2015,7 +2015,7 @@ gcal_year_view_init (GcalYearView *self)
guint i;
for (i = 0; i < 12; i++)
- self->events[i] = g_ptr_array_new ();
+ self->events[i] = g_ptr_array_new_with_free_func (g_object_unref);
gtk_widget_init_template (GTK_WIDGET (self));
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]