From f713a90ea3fca2d482a265f08841f7e40f8f7c99 Mon Sep 17 00:00:00 2001 From: Victor Toso Date: Sat, 1 Oct 2016 00:16:20 +0200 Subject: [PATCH] time-selector: Fix GDateTime leak By using finalize and dispose methods and calling the proper free methods calls. 8,806 (64 direct, 8,742 indirect) bytes in 2 blocks are definitely lost in loss record 18,367 of 18,534 at 0x4C2DB9D: malloc (vg_replace_malloc.c:299) by 0x9A0C90E: g_malloc (gmem.c:94) by 0x9A26A55: g_slice_alloc (gslice.c:1025) by 0x9A26A95: g_slice_alloc0 (gslice.c:1051) by 0x99E8DC4: g_date_time_alloc (gdatetime.c:428) by 0x99E8FA3: g_date_time_from_instant (gdatetime.c:524) by 0x99E933F: g_date_time_new_from_timeval (gdatetime.c:647) by 0x99E93A5: g_date_time_new_now (gdatetime.c:705) by 0x99E93C4: g_date_time_new_now_local (gdatetime.c:728) by 0x445BED: gcal_time_selector_init (gcal-time-selector.c:249) by 0x9584B32: g_type_create_instance (gtype.c:1866) by 0x956BED0: g_object_new_internal (gobject.c:1783) https://bugzilla.gnome.org/show_bug.cgi?id=772272 --- src/gcal-time-selector.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/gcal-time-selector.c b/src/gcal-time-selector.c index 781bf9b0..54109c87 100644 --- a/src/gcal-time-selector.c +++ b/src/gcal-time-selector.c @@ -206,6 +206,21 @@ gcal_time_selector_set_time_format (GcalTimeSelector *selector, } } +static void +gcal_time_selector_finalize (GObject *object) +{ + GcalTimeSelector *self = GCAL_TIME_SELECTOR (object); + + g_clear_pointer (&self->time, g_date_time_unref); + G_OBJECT_CLASS (gcal_time_selector_parent_class)->finalize (object); +} + +static void +gcal_time_selector_dispose (GObject *object) +{ + G_OBJECT_CLASS (gcal_time_selector_parent_class)->dispose (object); +} + static void gcal_time_selector_class_init (GcalTimeSelectorClass *klass) { @@ -213,6 +228,8 @@ gcal_time_selector_class_init (GcalTimeSelectorClass *klass) object_class = G_OBJECT_CLASS (klass); object_class->constructed = gcal_time_selector_constructed; + object_class->dispose = gcal_time_selector_dispose; + object_class->finalize = gcal_time_selector_finalize; object_class->get_property = gcal_time_selector_get_property; object_class->set_property = gcal_time_selector_set_property;