From fe1d707a8ca1656063a1b93bf47a78ac20225d7b Mon Sep 17 00:00:00 2001 From: Rui Matos Date: Thu, 15 Oct 2015 19:34:40 +0200 Subject: [PATCH 1/4] monitor-manager-xrandr: Be more robust when reading XRROutputInfos We might get modes in XRROutputInfos that aren't in the XRRScreenResources we get earlier. This always seems to be transient, i.e. when it happens, the X server will usually send us a follow up RRScreenChangeNotify where we then get a "stable" view of the world again. In any case, when these glitches happen, we end up with NULL pointers in the MetaOutput->modes array which makes us crash later on. This patch ensures that doesn't happen. https://bugzilla.gnome.org/show_bug.cgi?id=756660 --- src/backends/x11/meta-monitor-manager-xrandr.c | 42 ++++++++++++++++++-------- 1 file changed, 29 insertions(+), 13 deletions(-) diff --git a/src/backends/x11/meta-monitor-manager-xrandr.c b/src/backends/x11/meta-monitor-manager-xrandr.c index 9c65cab..6653b33 100644 --- a/src/backends/x11/meta-monitor-manager-xrandr.c +++ b/src/backends/x11/meta-monitor-manager-xrandr.c @@ -406,6 +406,32 @@ output_get_suggested_y (MetaMonitorManagerXrandr *manager_xrandr, return -1; } +static void +output_get_modes (MetaMonitorManager *manager, + MetaOutput *meta_output, + XRROutputInfo *output) +{ + guint j, k; + guint n_actual_modes; + + meta_output->modes = g_new0 (MetaMonitorMode *, output->nmode); + + n_actual_modes = 0; + for (j = 0; j < (guint)output->nmode; j++) + { + for (k = 0; k < manager->n_modes; k++) + { + if (output->modes[j] == (XID)manager->modes[k].mode_id) + { + meta_output->modes[n_actual_modes] = &manager->modes[k]; + n_actual_modes += 1; + break; + } + } + } + meta_output->n_modes = n_actual_modes; +} + static char * get_xmode_name (XRRModeInfo *xmode) { @@ -548,6 +574,8 @@ meta_monitor_manager_xrandr_read_current (MetaMonitorManager *manager) MetaOutput *meta_output; output = XRRGetOutputInfo (manager_xrandr->xdisplay, resources, resources->outputs[i]); + if (!output) + continue; meta_output = &manager->outputs[n_actual_outputs]; @@ -596,19 +624,7 @@ meta_monitor_manager_xrandr_read_current (MetaMonitorManager *manager) meta_output->suggested_x = output_get_suggested_x (manager_xrandr, meta_output); meta_output->suggested_y = output_get_suggested_y (manager_xrandr, meta_output); - meta_output->n_modes = output->nmode; - meta_output->modes = g_new0 (MetaMonitorMode *, meta_output->n_modes); - for (j = 0; j < meta_output->n_modes; j++) - { - for (k = 0; k < manager->n_modes; k++) - { - if (output->modes[j] == (XID)manager->modes[k].mode_id) - { - meta_output->modes[j] = &manager->modes[k]; - break; - } - } - } + output_get_modes (manager, meta_output, output); meta_output->preferred_mode = meta_output->modes[0]; meta_output->n_possible_crtcs = output->ncrtc; -- 2.5.0