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 920121d9f9babb30
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
     1.1 --- a/src/SDL_hints.c	Mon Oct 27 19:53:44 2014 -0400
     1.2 +++ b/src/SDL_hints.c	Wed Oct 29 20:20:47 2014 +0100
     1.3 @@ -149,6 +149,11 @@
     1.4          /* Need to add a hint entry for this watcher */
     1.5          hint = (SDL_Hint *)SDL_malloc(sizeof(*hint));
     1.6          if (!hint) {
     1.7 +            if(entry)
     1.8 +            {
     1.9 +              SDL_free(entry);
    1.10 +              entry = NULL;
    1.11 +            }
    1.12              return;
    1.13          }
    1.14          hint->name = SDL_strdup(name);