Fixed bug 4708 - testdropfile: double-free
authorSam Lantinga <slouken@libsdl.org>
Wed, 03 Jul 2019 02:37:15 -0700
changeset 12925c6c6e400a007
parent 12924 9cbdc68e4a5e
child 12926 b5cd5e1e4440
Fixed bug 4708 - testdropfile: double-free


Juha Niemimäki

SDLTest_CommonEvent seems to free the file name so testdropfile prints some garbage to console and crashes when freeing the name again.
test/testdropfile.c
     1.1 --- a/test/testdropfile.c	Tue Jul 02 16:49:35 2019 -0400
     1.2 +++ b/test/testdropfile.c	Wed Jul 03 02:37:15 2019 -0700
     1.3 @@ -75,8 +75,6 @@
     1.4      while (!done) {
     1.5          /* Check for events */
     1.6          while (SDL_PollEvent(&event)) {
     1.7 -            SDLTest_CommonEvent(state, &event, &done);
     1.8 -
     1.9              if (event.type == SDL_DROPBEGIN) {
    1.10                  SDL_Log("Drop beginning on window %u", (unsigned int) event.drop.windowID);
    1.11              } else if (event.type == SDL_DROPCOMPLETE) {
    1.12 @@ -85,8 +83,11 @@
    1.13                  const char *typestr = (event.type == SDL_DROPFILE) ? "File" : "Text";
    1.14                  char *dropped_filedir = event.drop.file;
    1.15                  SDL_Log("%s dropped on window %u: %s", typestr, (unsigned int) event.drop.windowID, dropped_filedir);
    1.16 -                SDL_free(dropped_filedir);
    1.17 +                /* Normally you'd have to do this, but this is freed in SDLTest_CommonEvent() */
    1.18 +                /*SDL_free(dropped_filedir);*/
    1.19              }
    1.20 +
    1.21 +            SDLTest_CommonEvent(state, &event, &done);
    1.22          }
    1.23      }
    1.24