Blob Blame History Raw
From 4020cddaf71e8868c03f0136964a6429af313b54 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Marco=20Trevisan=20=28Trevi=C3=B1o=29?= <mail@3v1n0.net>
Date: Wed, 24 Jul 2019 15:40:06 +0200
Subject: [PATCH 20/28] monitor: Free the existing mode if replacing it

When adding a mode and replacing it, we need to free it after that we've added
it to the table. Since the mode_ids table has not ownership on the mode id or
on the mode itself, we need to free it once replaced.

https://gitlab.gnome.org/GNOME/mutter/merge_requests/682
---
 src/backends/meta-monitor.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/src/backends/meta-monitor.c b/src/backends/meta-monitor.c
index 9a412a612..ec583aa13 100644
--- a/src/backends/meta-monitor.c
+++ b/src/backends/meta-monitor.c
@@ -437,60 +437,63 @@ generate_mode_id (MetaMonitorModeSpec *monitor_mode_spec)
   is_interlaced = !!(monitor_mode_spec->flags & META_CRTC_MODE_FLAG_INTERLACE);
   g_ascii_dtostr (refresh_rate_str, G_ASCII_DTOSTR_BUF_SIZE,
                   monitor_mode_spec->refresh_rate);
 
   return g_strdup_printf ("%dx%d%s@%s",
                           monitor_mode_spec->width,
                           monitor_mode_spec->height,
                           is_interlaced ? "i" : "",
                           refresh_rate_str);
 }
 
 static gboolean
 meta_monitor_add_mode (MetaMonitor     *monitor,
                        MetaMonitorMode *monitor_mode,
                        gboolean         replace)
 {
   MetaMonitorPrivate *priv = meta_monitor_get_instance_private (monitor);
   MetaMonitorMode *existing_mode;
 
   existing_mode = g_hash_table_lookup (priv->mode_ids,
                                        meta_monitor_mode_get_id (monitor_mode));
   if (existing_mode && !replace)
     return FALSE;
 
   if (existing_mode)
     priv->modes = g_list_remove (priv->modes, existing_mode);
 
   priv->modes = g_list_append (priv->modes, monitor_mode);
   g_hash_table_replace (priv->mode_ids, monitor_mode->id, monitor_mode);
 
+  if (existing_mode)
+    meta_monitor_mode_free (existing_mode);
+
   return TRUE;
 }
 
 static MetaMonitorModeSpec
 meta_monitor_create_spec (MetaMonitor  *monitor,
                           int           width,
                           int           height,
                           MetaCrtcMode *crtc_mode)
 {
   MetaOutput *output = meta_monitor_get_main_output (monitor);
 
   if (meta_monitor_transform_is_rotated (output->panel_orientation_transform))
     {
       int temp = width;
       width = height;
       height = temp;
     }
 
   return (MetaMonitorModeSpec) {
     .width = width,
     .height = height,
     .refresh_rate = crtc_mode->refresh_rate,
     .flags = crtc_mode->flags & HANDLED_CRTC_MODE_FLAGS
   };
 }
 
 static void
 meta_monitor_normal_generate_modes (MetaMonitorNormal *monitor_normal)
 {
   MetaMonitor *monitor = META_MONITOR (monitor_normal);
-- 
2.26.2