diff options
author | Alessandro Bono <alessandro.bono369@gmail.com> | 2022-09-07 10:42:55 +0200 |
---|---|---|
committer | Ray Strode <halfline@gmail.com> | 2022-09-27 15:18:26 +0000 |
commit | a95d9169a1ce0f0c280da4152269551651ea902b (patch) | |
tree | 6be259e7ec8320cb2a434dc37c8cfffd1859f86c /daemon/gdm-display.c | |
parent | acf70eda857598de6da5978bdfe88a1b28509db1 (diff) | |
download | gdm-a95d9169a1ce0f0c280da4152269551651ea902b.tar.gz |
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
Diffstat (limited to 'daemon/gdm-display.c')
-rw-r--r-- | daemon/gdm-display.c | 11 |
1 files changed, 3 insertions, 8 deletions
diff --git a/daemon/gdm-display.c b/daemon/gdm-display.c index 46d5a773..492cfb08 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); |