From 3226d4f312b8470636e6a474dd9c6d54dc592d34 Mon Sep 17 00:00:00 2001 From: Misa Date: Mon, 15 Feb 2021 19:11:51 -0800 Subject: [PATCH] Free loaded file in editorclass::getLevelMetadata() This fixes memory leaking every single time a file gets loaded(!) when the list of custom levels gets loaded(!!!), which Valgrind reports. This memory leak is completely my bad; 2.2 properly frees the loaded file, and VCE uses an std::unique_ptr - which I decided to ignore and not think about why it would be there. It's safe to do this free after uMem gets copied into std::string; although, in the future, I *am* thinking about refactoring this function (and the tag finder function) to not use std::strings, and I'll have to be careful to make sure that the memory management with the file is correct when I do so. --- desktop_version/src/editor.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/desktop_version/src/editor.cpp b/desktop_version/src/editor.cpp index 2a1ebe0b..149c0ef9 100644 --- a/desktop_version/src/editor.cpp +++ b/desktop_version/src/editor.cpp @@ -247,6 +247,8 @@ bool editorclass::getLevelMetaData(std::string& _path, LevelMetaData& _data ) std::string buf((char*) uMem); + FILESYSTEM_freeMemory(&uMem); + if (find_metadata(buf) == "") { printf("Couldn't load metadata for %s\n", _path.c_str());