Commit 3fc447dfc9162c302ad8c953d1e08b17fc879bf7

Sam Lantinga 2019-07-03T02:37:15

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.

diff --git a/test/testdropfile.c b/test/testdropfile.c
index c0cc7a5..97ab872 100644
--- a/test/testdropfile.c
+++ b/test/testdropfile.c
@@ -75,8 +75,6 @@ main(int argc, char *argv[])
     while (!done) {
         /* Check for events */
         while (SDL_PollEvent(&event)) {
-            SDLTest_CommonEvent(state, &event, &done);
-
             if (event.type == SDL_DROPBEGIN) {
                 SDL_Log("Drop beginning on window %u", (unsigned int) event.drop.windowID);
             } else if (event.type == SDL_DROPCOMPLETE) {
@@ -85,8 +83,11 @@ main(int argc, char *argv[])
                 const char *typestr = (event.type == SDL_DROPFILE) ? "File" : "Text";
                 char *dropped_filedir = event.drop.file;
                 SDL_Log("%s dropped on window %u: %s", typestr, (unsigned int) event.drop.windowID, dropped_filedir);
-                SDL_free(dropped_filedir);
+                /* Normally you'd have to do this, but this is freed in SDLTest_CommonEvent() */
+                /*SDL_free(dropped_filedir);*/
             }
+
+            SDLTest_CommonEvent(state, &event, &done);
         }
     }