Fixed bug 1805 - Memory Leak issue in src/video/x11/edid-parse.c file
authorSam Lantinga <slouken@libsdl.org>
Wed, 17 Apr 2013 01:38:59 -0700
changeset 70721d9b4b7a8ce3
parent 7071 82f17e656125
child 7073 873715d91f83
Fixed bug 1805 - Memory Leak issue in src/video/x11/edid-parse.c file

Nitz

In Function,

MonitorInfo *
decode_edid (const uchar *edid)

In this function "info" is going out of scope and leaks the storage it points to, if the first if condition get true:
if (!decode_header (edid))
return NULL;

So while returning from this if statement there should be free for "info" pointer.
src/video/x11/edid-parse.c
     1.1 --- a/src/video/x11/edid-parse.c	Wed Apr 17 01:35:10 2013 -0700
     1.2 +++ b/src/video/x11/edid-parse.c	Wed Apr 17 01:38:59 2013 -0700
     1.3 @@ -524,29 +524,17 @@
     1.4  
     1.5      decode_check_sum (edid, info);
     1.6      
     1.7 -    if (!decode_header (edid))
     1.8 +    if (!decode_header (edid) ||
     1.9 +        !decode_vendor_and_product_identification (edid, info) ||
    1.10 +        !decode_edid_version (edid, info) ||
    1.11 +        !decode_display_parameters (edid, info) ||
    1.12 +        !decode_color_characteristics (edid, info) ||
    1.13 +        !decode_established_timings (edid, info) ||
    1.14 +        !decode_standard_timings (edid, info) ||
    1.15 +        !decode_descriptors (edid, info)) {
    1.16 +        free(info);
    1.17  	return NULL;
    1.18 -
    1.19 -    if (!decode_vendor_and_product_identification (edid, info))
    1.20 -	return NULL;
    1.21 -
    1.22 -    if (!decode_edid_version (edid, info))
    1.23 -	return NULL;
    1.24 -
    1.25 -    if (!decode_display_parameters (edid, info))
    1.26 -	return NULL;
    1.27 -
    1.28 -    if (!decode_color_characteristics (edid, info))
    1.29 -	return NULL;
    1.30 -
    1.31 -    if (!decode_established_timings (edid, info))
    1.32 -	return NULL;
    1.33 -
    1.34 -    if (!decode_standard_timings (edid, info))
    1.35 -	return NULL;
    1.36 -    
    1.37 -    if (!decode_descriptors (edid, info))
    1.38 -	return NULL;
    1.39 +    }
    1.40      
    1.41      return info;
    1.42  }