[gdm: 1/4] gdm-display: Plug a memory leak




commit a95d9169a1ce0f0c280da4152269551651ea902b
Author: Alessandro Bono <alessandro bono369 gmail com>
Date:   Wed Sep 7 10:42:55 2022 +0200

    gdm-display: Plug a memory leak
    
    Use g_autofree to avoid manual memory handling. While at it use g_strdup_printf
    which is safer since it avoid us to calculate how much memory we need to allocate.
    
    Fixes: 08eee2ae1175cc43015329a00230f38066130c57

 daemon/gdm-display.c | 11 +++--------
 1 file changed, 3 insertions(+), 8 deletions(-)
---
diff --git a/daemon/gdm-display.c b/daemon/gdm-display.c
index 46d5a7732..492cfb086 100644
--- a/daemon/gdm-display.c
+++ b/daemon/gdm-display.c
@@ -1827,10 +1827,8 @@ gdm_display_set_windowpath (GdmDisplay *self)
         xcb_get_property_reply_t *get_property_reply = NULL;
         xcb_window_t root_window = XCB_WINDOW_NONE;
         const char *windowpath;
-        char *newwindowpath;
+        g_autofree gchar *newwindowpath = NULL;
         uint32_t num;
-        char nums[10];
-        int numn;
 
         priv = gdm_display_get_instance_private (self);
 
@@ -1868,13 +1866,10 @@ gdm_display_set_windowpath (GdmDisplay *self)
         num = ((uint32_t *) xcb_get_property_value (get_property_reply))[0];
 
         windowpath = getenv ("WINDOWPATH");
-        numn = snprintf (nums, sizeof (nums), "%u", num);
         if (!windowpath) {
-                newwindowpath = malloc (numn + 1);
-                sprintf (newwindowpath, "%s", nums);
+                newwindowpath = g_strdup_printf ("%u", num);
         } else {
-                newwindowpath = malloc (strlen (windowpath) + 1 + numn + 1);
-                sprintf (newwindowpath, "%s:%s", windowpath, nums);
+                newwindowpath = g_strdup_printf ("%s:%u", windowpath, num);
         }
 
         g_setenv ("WINDOWPATH", newwindowpath, TRUE);


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