Skip to content

Commit

Permalink
Fixed crash if allocation for touch device failed.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
philippwiesemann committed Jun 12, 2015
1 parent 7146874 commit d8c2b36
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/events/SDL_touch.c
Expand Up @@ -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;
Expand Down

0 comments on commit d8c2b36

Please sign in to comment.