[mutter] monitor-manager-xrandr: Fix small leak for invalid properties



commit 21bffe4aefdb375265db8148de75946189fc728b
Author: Jasper St. Pierre <jstpierre mecheye net>
Date:   Mon Sep 29 17:40:47 2014 -0600

    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 files 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 7f60f40..38edc7f 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


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]