Fixed bug 2647 - Memory leak in SDL_AddHintCallback function - SDL_hints.c
authorPhilipp Wiesemann <philipp.wiesemann@arcor.de>
Wed, 29 Oct 2014 20:20:47 +0100
changeset 9201 21d9f9babb30
parent 9200 bfdc18891a60
child 9202 01bb8e3ba14f
Fixed bug 2647 - Memory leak in SDL_AddHintCallback function - SDL_hints.c Nitz Variable entry going out of scope leaks the storage it points to, at: /* Need to add a hint entry for this watcher */ hint = (SDL_Hint *)SDL_malloc(sizeof(*hint)); if (!hint) { return; } Patch is attached.
src/SDL_hints.c
--- a/src/SDL_hints.c	Mon Oct 27 19:53:44 2014 -0400
+++ b/src/SDL_hints.c	Wed Oct 29 20:20:47 2014 +0100
@@ -149,6 +149,11 @@
         /* Need to add a hint entry for this watcher */
         hint = (SDL_Hint *)SDL_malloc(sizeof(*hint));
         if (!hint) {
+            if(entry)
+            {
+              SDL_free(entry);
+              entry = NULL;
+            }
             return;
         }
         hint->name = SDL_strdup(name);