From efbaeeffde86f96a9f5528b576b07afd18c784fb Mon Sep 17 00:00:00 2001 From: Misa Date: Mon, 15 Feb 2021 18:43:35 -0800 Subject: [PATCH] Clean up all leftover resources in cleanup() If there's a resource that doesn't otherwise need to be cleaned up and is still alive upon program shutdown, then it should go in cleanup(). This cleans up Screen, GraphicsResources, Graphics buffers, Graphics tiles, and musicclass audio upon program shutdown. Even we technically don't NEED to clean these resources up ourselves (the kernel is going to get rid of all of it anyway, else it'd be a security problem), I'm doing this because otherwise Valgrind will complain about these, and then it'd be difficult to see which memory leaks are real and which are just "well this isn't really a leak but you haven't freed this thing when the process exited, and that's technically what a memory leak is". These are all resources whose cleanup functions can be safely called even if they haven't initialized anything yet. --- desktop_version/src/main.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/desktop_version/src/main.cpp b/desktop_version/src/main.cpp index 83ef473b..2ff9c8bd 100644 --- a/desktop_version/src/main.cpp +++ b/desktop_version/src/main.cpp @@ -365,7 +365,13 @@ int main(int argc, char *argv[]) static void cleanup() { + /* Order matters! */ game.savestatsandsettings(); + gameScreen.destroy(); + graphics.grphx.destroy(); + graphics.destroy_buffers(); + graphics.destroy(); + music.destroy(); NETWORK_shutdown(); SDL_Quit(); FILESYSTEM_deinit();