[PATCH xinput 3/5] Don't leak output_info

Peter Hutterer peter.hutterer at who-t.net
Sun Feb 19 19:36:59 PST 2012


This inverts the logic to have a more obvious flow for freeing the
output_info.

==26716== 1,161 bytes in 8 blocks are definitely lost in loss record 5 of 7
==26716==    at 0x4A074CD: malloc (vg_replace_malloc.c:236)
==26716==    by 0x395D804ABA: XRRGetOutputInfo (in /usr/lib64/libXrandr.so.2.2.0)
==26716==    by 0x40932B: map_output_xrandr (transform.c:150)
==26716==    by 0x40982F: map_to_output (transform.c:263)
==26716==    by 0x4070A4: main (xinput.c:386)

Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
---
 src/transform.c |    8 +++++---
 1 files changed, 5 insertions(+), 3 deletions(-)

diff --git a/src/transform.c b/src/transform.c
index 7717ffb..3ea7ff8 100644
--- a/src/transform.c
+++ b/src/transform.c
@@ -148,14 +148,15 @@ map_output_xrandr(Display *dpy, int deviceid, const char *output_name)
     for (i = 0; i < res->noutput && !found; i++)
     {
         output_info = XRRGetOutputInfo(dpy, res, res->outputs[i]);
-        if (!output_info->crtc || output_info->connection != RR_Connected)
-            continue;
 
-        if (strcmp(output_info->name, output_name) == 0)
+        if (output_info->crtc && output_info->connection == RR_Connected &&
+            strcmp(output_info->name, output_name) == 0)
         {
             found = 1;
             break;
         }
+
+        XRRFreeOutputInfo(output_info);
     }
 
     /* crtc holds our screen info, need to compare to actual screen size */
@@ -169,6 +170,7 @@ map_output_xrandr(Display *dpy, int deviceid, const char *output_name)
                                   crtc_info->width, crtc_info->height);
         rc = apply_matrix(dpy, deviceid, &m);
         XRRFreeCrtcInfo(crtc_info);
+        XRRFreeOutputInfo(output_info);
     } else
         printf("Unable to find output '%s'. "
                 "Output may not be connected.\n", output_name);
-- 
1.7.7.5



More information about the xorg-devel mailing list