Fixed SDL_AddHintCallback() crashing if no more memory available.
authorPhilipp Wiesemann <philipp.wiesemann@arcor.de>
Wed, 29 Oct 2014 20:29:32 +0100
changeset 9202 01bb8e3ba14f
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
--- a/src/SDL_hints.c	Wed Oct 29 20:20:47 2014 +0100
+++ b/src/SDL_hints.c	Wed Oct 29 20:29:32 2014 +0100
@@ -137,6 +137,10 @@
     SDL_DelHintCallback(name, callback, userdata);
 
     entry = (SDL_HintWatch *)SDL_malloc(sizeof(*entry));
+    if (!entry) {
+        SDL_OutOfMemory();
+        return;
+    }
     entry->callback = callback;
     entry->userdata = userdata;
 
@@ -149,6 +153,7 @@
         /* Need to add a hint entry for this watcher */
         hint = (SDL_Hint *)SDL_malloc(sizeof(*hint));
         if (!hint) {
+            SDL_OutOfMemory();
             if(entry)
             {
               SDL_free(entry);