Fixed bug 1736 - Memory leak in X11_InitModes
authorSam Lantinga
Thu, 28 Feb 2013 22:20:25 -0800
changeset 6940142dcc136188
parent 6939 06a72f2f8b16
child 6941 9bb475091e51
Fixed bug 1736 - Memory leak in X11_InitModes

tomaszewski.p

XRRListOutputProperties allocates Atom* array, which is not freed.
XRRGetOutputProperty allocates 'unsigned char *prop' array, which is not freed.
src/video/x11/SDL_x11modes.c
     1.1 --- a/src/video/x11/SDL_x11modes.c	Thu Feb 28 21:48:12 2013 -0800
     1.2 +++ b/src/video/x11/SDL_x11modes.c	Thu Feb 28 22:20:25 2013 -0800
     1.3 @@ -576,26 +576,31 @@
     1.4                      int actual_format;
     1.5                      unsigned long nitems, bytes_after;
     1.6                      Atom actual_type;
     1.7 -   
     1.8 +
     1.9  	                if (props[i] == EDID) {
    1.10 -                        XRRGetOutputProperty(data->display, res->outputs[output], props[i],
    1.11 -                                             0, 100, False, False,
    1.12 -                                             AnyPropertyType,
    1.13 -                                             &actual_type, &actual_format,
    1.14 -                                             &nitems, &bytes_after, &prop);
    1.15 -
    1.16 -                        MonitorInfo *info = decode_edid(prop);
    1.17 -                        if (info) {
    1.18 -#ifdef X11MODES_DEBUG
    1.19 -                            printf("Found EDID data for %s\n", output_info->name);
    1.20 -                            dump_monitor_info(info);
    1.21 -#endif
    1.22 -                            SDL_strlcpy(display_name, info->dsc_product_name, sizeof(display_name));
    1.23 -                            free(info);
    1.24 +                        if (XRRGetOutputProperty(data->display,
    1.25 +                                                 res->outputs[output], props[i],
    1.26 +                                                 0, 100, False, False,
    1.27 +                                                 AnyPropertyType,
    1.28 +                                                 &actual_type, &actual_format,
    1.29 +                                                 &nitems, &bytes_after, &prop) == Success ) {
    1.30 +                            MonitorInfo *info = decode_edid(prop);
    1.31 +                            if (info) {
    1.32 +    #ifdef X11MODES_DEBUG
    1.33 +                                printf("Found EDID data for %s\n", output_info->name);
    1.34 +                                dump_monitor_info(info);
    1.35 +    #endif
    1.36 +                                SDL_strlcpy(display_name, info->dsc_product_name, sizeof(display_name));
    1.37 +                                free(info);
    1.38 +                            }
    1.39 +                            SDL_free(prop);
    1.40                          }
    1.41                          break;
    1.42                      }
    1.43                  }
    1.44 +                if (props) {
    1.45 +                    SDL_free(props);
    1.46 +                }
    1.47  
    1.48                  if (*display_name && inches) {
    1.49                      size_t len = SDL_strlen(display_name);