Wayland: Fixed crash if allocating memory for cursor failed.
authorPhilipp Wiesemann <philipp.wiesemann@arcor.de>
Wed, 02 Mar 2016 20:25:09 +0100
changeset 1009891b34fbbb88e
parent 10097 06085b9c73ef
child 10099 c7932bb6dcee
Wayland: Fixed crash if allocating memory for cursor failed.

Also added missing error message if first allocation failed.
src/video/wayland/SDL_waylandmouse.c
     1.1 --- a/src/video/wayland/SDL_waylandmouse.c	Wed Mar 02 20:24:43 2016 +0100
     1.2 +++ b/src/video/wayland/SDL_waylandmouse.c	Wed Mar 02 20:25:09 2016 +0100
     1.3 @@ -159,6 +159,11 @@
     1.4          SDL_VideoDevice *vd = SDL_GetVideoDevice ();
     1.5          SDL_VideoData *wd = (SDL_VideoData *) vd->driverdata;
     1.6          Wayland_CursorData *data = calloc (1, sizeof (Wayland_CursorData));
     1.7 +        if (!data) {
     1.8 +            SDL_OutOfMemory();
     1.9 +            free(cursor);
    1.10 +            return NULL;
    1.11 +        }
    1.12          cursor->driverdata = (void *) data;
    1.13  
    1.14          /* Assume ARGB8888 */
    1.15 @@ -187,6 +192,8 @@
    1.16          data->hot_y = hot_y;
    1.17          data->w = surface->w;
    1.18          data->h = surface->h;
    1.19 +    } else {
    1.20 +        SDL_OutOfMemory();
    1.21      }
    1.22  
    1.23      return cursor;
    1.24 @@ -200,6 +207,11 @@
    1.25      cursor = calloc(1, sizeof (*cursor));
    1.26      if (cursor) {
    1.27          Wayland_CursorData *data = calloc (1, sizeof (Wayland_CursorData));
    1.28 +        if (!data) {
    1.29 +            SDL_OutOfMemory();
    1.30 +            free(cursor);
    1.31 +            return NULL;
    1.32 +        }
    1.33          cursor->driverdata = (void *) data;
    1.34  
    1.35          data->buffer = WAYLAND_wl_cursor_image_get_buffer(wlcursor->images[0]);