From 21bffe4aefdb375265db8148de75946189fc728b Mon Sep 17 00:00:00 2001 From: "Jasper St. Pierre" Date: Mon, 29 Sep 2014 17:40:47 -0600 Subject: monitor-manager-xrandr: Fix small leak for invalid properties If the property is invalid, then we leak the allocated buffer. Make sure to free it in this case. --- src/backends/x11/meta-monitor-manager-xrandr.c | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/src/backends/x11/meta-monitor-manager-xrandr.c b/src/backends/x11/meta-monitor-manager-xrandr.c index 7f60f4075..38edc7fe8 100644 --- a/src/backends/x11/meta-monitor-manager-xrandr.c +++ b/src/backends/x11/meta-monitor-manager-xrandr.c @@ -144,7 +144,7 @@ static gboolean output_get_boolean_property (MetaMonitorManagerXrandr *manager_xrandr, MetaOutput *output, const char *propname) { - gboolean value; + gboolean value = FALSE; Atom atom, actual_type; int actual_format; unsigned long nitems, bytes_after; @@ -158,12 +158,12 @@ output_get_boolean_property (MetaMonitorManagerXrandr *manager_xrandr, &actual_type, &actual_format, &nitems, &bytes_after, &buffer); - if (actual_type != XA_CARDINAL || actual_format != 32 || - nitems < 1) - return FALSE; + if (actual_type != XA_CARDINAL || actual_format != 32 || nitems < 1) + goto out; value = ((int*)buffer)[0]; + out: XFree (buffer); return value; } @@ -187,7 +187,7 @@ static int output_get_backlight_xrandr (MetaMonitorManagerXrandr *manager_xrandr, MetaOutput *output) { - gboolean value; + int value = -1; Atom atom, actual_type; int actual_format; unsigned long nitems, bytes_after; @@ -201,14 +201,17 @@ output_get_backlight_xrandr (MetaMonitorManagerXrandr *manager_xrandr, &actual_type, &actual_format, &nitems, &bytes_after, &buffer); - if (actual_type != XA_INTEGER || actual_format != 32 || - nitems < 1) - return -1; + if (actual_type != XA_INTEGER || actual_format != 32 || nitems < 1) + goto out; value = ((int*)buffer)[0]; + out: XFree (buffer); - return normalize_backlight (output, value); + if (value > 0) + return normalize_backlight (output, value); + else + return -1; } static void -- cgit v1.2.1