Fixed SDL_AddHintCallback() crashing if no more memory available.
authorPhilipp Wiesemann
Wed, 29 Oct 2014 20:29:32 +0100
changeset 920201bb8e3ba14f
parent 9201 21d9f9babb30
child 9203 874b59c43a3f
Fixed SDL_AddHintCallback() crashing if no more memory available.

The return value of SDL_malloc() was not checked and NULL therefore not handled.
Also added setting of error message for the other SDL_malloc() in this function.
src/SDL_hints.c
     1.1 --- a/src/SDL_hints.c	Wed Oct 29 20:20:47 2014 +0100
     1.2 +++ b/src/SDL_hints.c	Wed Oct 29 20:29:32 2014 +0100
     1.3 @@ -137,6 +137,10 @@
     1.4      SDL_DelHintCallback(name, callback, userdata);
     1.5  
     1.6      entry = (SDL_HintWatch *)SDL_malloc(sizeof(*entry));
     1.7 +    if (!entry) {
     1.8 +        SDL_OutOfMemory();
     1.9 +        return;
    1.10 +    }
    1.11      entry->callback = callback;
    1.12      entry->userdata = userdata;
    1.13  
    1.14 @@ -149,6 +153,7 @@
    1.15          /* Need to add a hint entry for this watcher */
    1.16          hint = (SDL_Hint *)SDL_malloc(sizeof(*hint));
    1.17          if (!hint) {
    1.18 +            SDL_OutOfMemory();
    1.19              if(entry)
    1.20              {
    1.21                SDL_free(entry);