Avoid memory leak in ddc resort() if find_header() fails
authorAlan Coopersmith <alan.coopersmith@oracle.com>
Sun, 27 Jan 2013 23:42:02 +0000 (15:42 -0800)
committerAlan Coopersmith <alan.coopersmith@oracle.com>
Wed, 6 Feb 2013 02:35:03 +0000 (18:35 -0800)
Call find_header first, returning on failure before calling malloc.

Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
Reviewed-by: Peter Hutterer <peter.hutterer@who-t.net>
hw/xfree86/ddc/ddc.c

index 28c9696..44c1d53 100644 (file)
@@ -91,15 +91,16 @@ resort(unsigned char *s_block)
     unsigned char *d_new, *d_ptr, *d_end, *s_ptr, *s_end;
     unsigned char tmp;
 
+    s_ptr = find_header(s_block);
+    if (!s_ptr)
+        return NULL;
     s_end = s_block + EDID1_LEN;
+
     d_new = malloc(EDID1_LEN);
     if (!d_new)
         return NULL;
     d_end = d_new + EDID1_LEN;
 
-    s_ptr = find_header(s_block);
-    if (!s_ptr)
-        return NULL;
     for (d_ptr = d_new; d_ptr < d_end; d_ptr++) {
         tmp = *(s_ptr++);
         *d_ptr = tmp;