From d8c2b36c21f267eb7de90fbf02e7ddfe348adf0b Mon Sep 17 00:00:00 2001 From: Philipp Wiesemann Date: Fri, 12 Jun 2015 21:10:31 +0200 Subject: [PATCH] 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 | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/events/SDL_touch.c b/src/events/SDL_touch.c index 58581b4e7..1b477ea7d 100644 --- a/src/events/SDL_touch.c +++ b/src/events/SDL_touch.c @@ -145,13 +145,16 @@ SDL_AddTouch(SDL_TouchID touchID, const char *name) } SDL_touchDevices = touchDevices; - index = SDL_num_touch++; + index = SDL_num_touch; SDL_touchDevices[index] = (SDL_Touch *) SDL_malloc(sizeof(*SDL_touchDevices[index])); if (!SDL_touchDevices[index]) { return SDL_OutOfMemory(); } + /* Added touch to list */ + ++SDL_num_touch; + /* we're setting the touch properties */ SDL_touchDevices[index]->id = touchID; SDL_touchDevices[index]->num_fingers = 0;