[Xfce4-commits] [apps/xfce4-notifyd] 01/02: Fix some memory leaks

noreply at xfce.org noreply at xfce.org
Tue Aug 29 23:39:44 CEST 2017


This is an automated email from the git hooks/post-receive script.

o   c   h   o   s   i       p   u   s   h   e   d       a       c   o   m   m   i   t       t   o       b   r   a   n   c   h       m   a   s   t   e   r   
   in repository apps/xfce4-notifyd.

commit b6315f23d31d8e9ef1b005042337ebda32a1898f
Author: Florian Schüller <florian.schueller at gmail.com>
Date:   Sun Aug 27 01:43:47 2017 +0200

    Fix some memory leaks
---
 xfce4-notifyd-config/main.c        | 11 ++++++-----
 xfce4-notifyd/xfce-notify-daemon.c | 39 ++++++++++++++++++++++++++++++++++----
 xfce4-notifyd/xfce-notify-log.c    | 21 ++++++++++++++------
 3 files changed, 56 insertions(+), 15 deletions(-)

diff --git a/xfce4-notifyd-config/main.c b/xfce4-notifyd-config/main.c
index 1f41e70..39be4af 100644
--- a/xfce4-notifyd-config/main.c
+++ b/xfce4-notifyd-config/main.c
@@ -577,17 +577,16 @@ xfce4_notifyd_log_populate (NotificationLogWidgets *log_widgets)
             gtk_label_set_ellipsize (GTK_LABEL (body), PANGO_ELLIPSIZE_END);
             tmp = g_key_file_get_string (notify_log, group, "app_icon", NULL);
             notify_log_icon_path = g_strconcat (notify_log_icon_folder , tmp, ".png", NULL);
-            if (g_file_test (notify_log_icon_path, G_FILE_TEST_EXISTS))
-            {
+            if (g_file_test (notify_log_icon_path, G_FILE_TEST_EXISTS)) {
                 pixbuf = gdk_pixbuf_new_from_file_at_scale (notify_log_icon_path,
                                                             24, 24, FALSE, NULL);
                 app_icon = gtk_image_new_from_pixbuf (pixbuf);
-            }
-            else
-            {
+                g_object_unref(pixbuf);
+            } else {
                 app_icon = gtk_image_new_from_icon_name (tmp, GTK_ICON_SIZE_LARGE_TOOLBAR);
                 gtk_image_set_pixel_size (GTK_IMAGE (app_icon), 24);
             }
+            g_free (notify_log_icon_path);
             g_free (tmp);
             gtk_widget_set_margin_start (app_icon, 3);
             tmp = g_key_file_get_string (notify_log, group, "expire-timeout", NULL);
@@ -632,6 +631,8 @@ xfce4_notifyd_log_populate (NotificationLogWidgets *log_widgets)
         g_key_file_free (notify_log);
     }
 
+    g_free(notify_log_icon_folder);
+
     gtk_widget_show_all (log_listbox);
 
     /* Update "open file" and "clear log" buttons sensitivity */
diff --git a/xfce4-notifyd/xfce-notify-daemon.c b/xfce4-notifyd/xfce-notify-daemon.c
index 0d67431..dcac2ee 100644
--- a/xfce4-notifyd/xfce-notify-daemon.c
+++ b/xfce4-notifyd/xfce-notify-daemon.c
@@ -1059,6 +1059,7 @@ notify_update_known_applications (XfconfChannel *channel, gchar *new_app_name)
         }
     }
     xfconf_array_free (known_applications);
+    g_free(val);
 }
 
 static gboolean
@@ -1101,7 +1102,7 @@ notify_notify (XfceNotifyGBus *skeleton,
     GdkPixbuf *pix = NULL;
     GVariant *image_data = NULL;
     const gchar *image_path = NULL;
-    const gchar *desktop_id = NULL;
+    gchar *desktop_id = NULL;
     gchar *new_app_name;
     gint value_hint = 0;
     gboolean value_hint_set = FALSE;
@@ -1116,7 +1117,7 @@ notify_notify (XfceNotifyGBus *skeleton,
 
     while ((item = g_variant_iter_next_value (&iter)))
     {
-        const char *key;
+        gchar *key;
         GVariant   *value;
 
         g_variant_get (item,
@@ -1132,24 +1133,31 @@ notify_notify (XfceNotifyGBus *skeleton,
                 /* don't expire urgent notifications */
                 expire_timeout = 0;
             }
+            g_variant_unref(value);
         }
         else if ((g_strcmp0 (key, "image_data") == 0) ||
                  (g_strcmp0 (key, "icon_data") == 0)  ||
                  (g_strcmp0 (key, "image-data") == 0) ||
                  (g_strcmp0 (key, "icon-data") == 0))
         {
+            if (image_data) {
+                g_variant_unref(image_data);
+            }
             image_data = value;
         }
         else if ((g_strcmp0 (key, "image-path") == 0) ||
                  (g_strcmp0 (key, "image_path") == 0))
         {
             image_path = g_variant_get_string (value, NULL);
+            g_variant_unref(value);
         }
         else if ((g_strcmp0 (key, "desktop_entry") == 0) ||
                  (g_strcmp0 (key, "desktop-entry") == 0))
         {
             if (g_variant_is_of_type (value, G_VARIANT_TYPE_STRING))
-                desktop_id = g_variant_get_string (value, NULL);
+                desktop_id = g_variant_dup_string (value, NULL);
+
+            g_variant_unref(value);
         }
         else if (g_strcmp0 (key, "value") == 0)
         {
@@ -1158,14 +1166,29 @@ notify_notify (XfceNotifyGBus *skeleton,
                 value_hint = g_variant_get_int32 (value);
                 value_hint_set = TRUE;
             }
+            g_variant_unref(value);
         }
         else if (g_strcmp0 (key, "transient") == 0)
+        {
             transient = TRUE;
+            g_variant_unref(value);
+        }
         else if (g_strcmp0 (key, "x-canonical-private-icon-only") == 0)
+        {
             x_canonical = TRUE;
+            g_variant_unref(value);
+        }
         else if (g_strcmp0 (key, "urgency") == 0)
+        {
             g_warning ("the urgency bit is set");
+            g_variant_unref(value);
+        }
+        else
+        {
+            g_variant_unref(value);
+        }
 
+        g_free(key);
         g_variant_unref (item);
     }
 
@@ -1204,6 +1227,8 @@ notify_notify (XfceNotifyGBus *skeleton,
             }
 
             xfce_notify_gbus_complete_notify(skeleton, invocation, OUT_id);
+            g_variant_unref(image_data);
+            g_free(desktop_id);
             return TRUE;
         }
     }
@@ -1257,7 +1282,6 @@ notify_notify (XfceNotifyGBus *skeleton,
             xfce_notify_window_set_icon_pixbuf(window, pix);
             g_object_unref(G_OBJECT(pix));
         }
-        g_variant_unref(image_data);
     }
     else if (image_path) {
         xfce_notify_window_set_icon_name (window, image_path);
@@ -1317,6 +1341,12 @@ notify_notify (XfceNotifyGBus *skeleton,
 
     xfce_notify_gbus_complete_notify(skeleton, invocation, OUT_id);
 
+    g_free(new_app_name);
+    if (image_data)
+        g_variant_unref(image_data);
+    if (desktop_id)
+        g_free(desktop_id);
+
     return TRUE;
 }
 
@@ -1390,6 +1420,7 @@ xfce_notify_daemon_set_theme(XfceNotifyDaemon *xndaemon,
         g_free (file);
         file = g_strconcat("themes/", theme, "/xfce-notify-4.0/gtk.css", NULL);
         files = xfce_resource_lookup_all(XFCE_RESOURCE_DATA, file);
+        g_free(file);
         if (!files || !files[0])
         {
             g_warning ("theme '%s' is not found anywhere is user themes directories", theme);
diff --git a/xfce4-notifyd/xfce-notify-log.c b/xfce4-notifyd/xfce-notify-log.c
index 5b756f2..1b0fc25 100644
--- a/xfce4-notifyd/xfce-notify-log.c
+++ b/xfce4-notifyd/xfce-notify-log.c
@@ -73,6 +73,7 @@ notify_pixbuf_from_image_data(GVariant *image_data)
 
     data = (guchar *) g_memdup (g_variant_get_data (pixel_data),
                                 g_variant_get_size (pixel_data));
+    g_variant_unref(pixel_data);
 
     pix = gdk_pixbuf_new_from_data(data,
                                    GDK_COLORSPACE_RGB, has_alpha,
@@ -114,15 +115,15 @@ void xfce_notify_log_insert (const gchar *app_name,
 {
     GKeyFile *notify_log;
     gchar *notify_log_path;
-    const gchar *timeout;
-    const gchar *group;
+    gchar *timeout;
+    gchar *group;
     gchar **groups;
     gint i;
     gint j = 0;
     GDateTime *now;
     gchar *timestamp;
     GBytes *image_bytes;
-    const gchar *icon_name;
+    gchar *icon_name;
     GdkPixbuf *pixbuf = NULL;
     gchar *notify_log_icon_folder;
     gchar *notify_log_icon_path;
@@ -140,7 +141,9 @@ void xfce_notify_log_insert (const gchar *app_name,
 
         now = g_date_time_new_now_local ();
         timestamp = g_date_time_format (now, "%FT%T");
+        g_date_time_unref (now);
         group = g_strdup_printf ("%s", timestamp);
+        g_free(timestamp);
 
         g_key_file_set_string (notify_log, group, "app_name", app_name);
         g_key_file_set_string (notify_log, group, "summary", summary);
@@ -148,30 +151,35 @@ void xfce_notify_log_insert (const gchar *app_name,
         if (image_data) {
             image_bytes = g_variant_get_data_as_bytes (image_data);
             icon_name = g_compute_checksum_for_bytes (G_CHECKSUM_MD5, image_bytes);
+            g_bytes_unref(image_bytes);
             pixbuf = notify_pixbuf_from_image_data (image_data);
             if (pixbuf) {
                 notify_log_icon_folder = xfce_resource_save_location (XFCE_RESOURCE_CACHE,
                                                                       XFCE_NOTIFY_ICON_PATH, TRUE);
                 notify_log_icon_path = g_strconcat (notify_log_icon_folder , icon_name, ".png", NULL);
+                g_free(notify_log_icon_folder);
                 if (!g_file_test (notify_log_icon_path, G_FILE_TEST_EXISTS)) {
                     if (!gdk_pixbuf_save (pixbuf, notify_log_icon_path, "png", NULL, NULL))
                         g_warning ("Could not save the pixbuf to: %s", notify_log_icon_path);
                 }
+                g_free(notify_log_icon_path);
                 g_object_unref (G_OBJECT (pixbuf));
             }
+            g_key_file_set_string (notify_log, group, "app_icon", icon_name);
+            g_free(icon_name);
         }
         else if (image_path) {
-            icon_name = image_path;
+            g_key_file_set_string (notify_log, group, "app_icon", image_path);
         }
         else if (app_icon && (g_strcmp0 (app_icon, "") != 0)) {
-            icon_name = app_icon;
+            g_key_file_set_string (notify_log, group, "app_icon", app_icon);
         }
 //        else
 //            g_warning ("everything failed. :'(");
 
-        g_key_file_set_string (notify_log, group, "app_icon", icon_name);
         timeout = g_strdup_printf ("%d", expire_timeout);
         g_key_file_set_string (notify_log, group, "expire-timeout", timeout);
+        g_free(timeout);
         for (i = 0; actions && actions[i]; i += 2) {
             const gchar *cur_action_id = actions[i];
             const gchar *cur_button_text = actions[i+1];
@@ -184,6 +192,7 @@ void xfce_notify_log_insert (const gchar *app_name,
 
         g_key_file_save_to_file (notify_log, notify_log_path, NULL);
         g_key_file_free (notify_log);
+        g_free(group);
     }
     else
         g_warning ("Unable to open cache file");

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the Xfce4-commits mailing list