Fixed crash if allocation for touch device failed.
authorPhilipp Wiesemann <philipp.wiesemann@arcor.de>
Fri, 12 Jun 2015 21:10:31 +0200
changeset 97303136a8c1cf0b
parent 9729 64f0929bcd2e
child 9731 a8140c580b85
Fixed crash if allocation for touch device failed.

If the allocation of an SDL_Touch failed, the number of touch devices was still
increased. Later access of the SDL_Touch would then have dereferenced the NULL.
src/events/SDL_touch.c
     1.1 --- a/src/events/SDL_touch.c	Fri Jun 12 11:58:31 2015 -0400
     1.2 +++ b/src/events/SDL_touch.c	Fri Jun 12 21:10:31 2015 +0200
     1.3 @@ -145,13 +145,16 @@
     1.4      }
     1.5  
     1.6      SDL_touchDevices = touchDevices;
     1.7 -    index = SDL_num_touch++;
     1.8 +    index = SDL_num_touch;
     1.9  
    1.10      SDL_touchDevices[index] = (SDL_Touch *) SDL_malloc(sizeof(*SDL_touchDevices[index]));
    1.11      if (!SDL_touchDevices[index]) {
    1.12          return SDL_OutOfMemory();
    1.13      }
    1.14  
    1.15 +    /* Added touch to list */
    1.16 +    ++SDL_num_touch;
    1.17 +
    1.18      /* we're setting the touch properties */
    1.19      SDL_touchDevices[index]->id = touchID;
    1.20      SDL_touchDevices[index]->num_fingers = 0;