Subject: [PATCH] Plug memory leak in GTK x-display-monitor-attributes-list

From: Alex <[email-masked]>
Date: Sat, 06 Apr 2019 23:16:53 -0600

Also declare `name' in MonitorInfo const to satisfy the compiler.

Is it too late to push a memory leak fix like this to emacs-26?

>From b9c71187840f72f5145da5794e1ca69d4a074654 Mon Sep 17 00:00:00 2001
From: Alexander Gramiak <[email-masked]>
Date: Sat, 6 Apr 2019 23:02:24 -0600
Subject: [PATCH] Plug memory leak in GTK x-display-monitor-attributes-list

* src/xfns.c (x-display-monitor-attributes-list): Plug memory leak and
  don't needlessly duplicate the model name.

* src/frame.h (MonitorInfo): Declare name as pointing to const char.
---
 src/frame.h | 2 +-
 src/xfns.c  | 3 ++-
 2 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/src/frame.h b/src/frame.h
index ed62e7ace0..b1eedf36a3 100644
--- a/src/frame.h
+++ b/src/frame.h
@@ -1648,7 +1648,7 @@ flush_frame (struct frame *f)
 struct MonitorInfo {
   XRectangle geom, work;
   int mm_width, mm_height;
-  char *name;
+  const char *name;
 };
 
 extern void free_monitors (struct MonitorInfo *monitors, int n_monitors);
diff --git a/src/xfns.c b/src/xfns.c
index f238a3daa1..396e77c1db 100644
--- a/src/xfns.c
+++ b/src/xfns.c
@@ -5030,7 +5030,7 @@ Internal use only, use `display-monitor-attributes-list' instead.  */)
       mi->mm_height = height_mm;
 
 #if GTK_CHECK_VERSION (3, 22, 0)
-      mi->name = g_strdup (gdk_monitor_get_model (monitor));
+      mi->name = gdk_monitor_get_model (monitor);
 #elif GTK_CHECK_VERSION (2, 14, 0)
       mi->name = gdk_screen_get_monitor_plug_name (gscreen, i);
 #endif
@@ -5041,6 +5041,7 @@ Internal use only, use `display-monitor-attributes-list' instead.  */)
                                                  primary_monitor,
                                                  monitor_frames,
                                                  source);
+  xfree (monitors);
   unblock_input ();
 #else  /* not USE_GTK */
 
-- 
2.21.0