[gnome-todo/feature/unref-fixes: 2/3] background: Use g_autoptr to fix some leaks




commit 5943b6de370b5ed55ceb662fec08f3c3be19b9c8
Author: Niels De Graef <nielsdegraef gmail com>
Date:   Fri Oct 8 19:07:27 2021 +0200

    background: Use g_autoptr to fix some leaks
    
    We were leaking some `GDateTime`s and a few strings. This commit cleans
    it up with g_autoptr().

 src/plugins/background/gtd-plugin-background.c | 16 +++++++---------
 1 file changed, 7 insertions(+), 9 deletions(-)
---
diff --git a/src/plugins/background/gtd-plugin-background.c b/src/plugins/background/gtd-plugin-background.c
index 01340154..a73c8b9d 100644
--- a/src/plugins/background/gtd-plugin-background.c
+++ b/src/plugins/background/gtd-plugin-background.c
@@ -261,6 +261,7 @@ is_today (GDateTime *now,
          g_date_time_get_day_of_month (dt) == g_date_time_get_day_of_month (now);
 }
 
+/* Returns: (transfer container) (element-type Gtd.Task): */
 static GList*
 get_tasks_for_today (guint *n_events)
 {
@@ -286,8 +287,8 @@ get_tasks_for_today (guint *n_events)
 
       for (j = 0; j < g_list_model_get_n_items (list); j++)
         {
-          GDateTime *due_date;
-          GtdTask *task;
+          g_autoptr (GtdTask) task = NULL;
+          g_autoptr (GDateTime) due_date = NULL;
 
           task = g_list_model_get_item (list, j);
 
@@ -310,13 +311,13 @@ get_tasks_for_today (guint *n_events)
 static void
 send_notification (GtdPluginBackground *self)
 {
-  GNotification *notification;
+  g_autoptr (GNotification) notification = NULL;
   GApplication *app;
   GtdWindow *window;
   guint n_tasks;
-  GList *tasks;
-  gchar *title;
-  gchar *body;
+  g_autoptr (GList) tasks = NULL;
+  g_autofree char *title = NULL;
+  g_autofree char *body = NULL;
 
   window = GTD_WINDOW (get_window ());
 
@@ -352,9 +353,6 @@ send_notification (GtdPluginBackground *self)
   g_notification_set_default_action (notification, "app.activate");
 
   g_application_send_notification (app, AUTOSTART_NOTIFICATION_ID, notification);
-
-  g_clear_pointer (&tasks, g_list_free);
-  g_clear_object (&notification);
 }
 
 /*


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