From bd257153dc9748bd9ab3f580437c3a28cc5348ab Mon Sep 17 00:00:00 2001 From: "Wilson E. Alvarez" Date: Wed, 23 Aug 2017 20:54:02 -0400 Subject: [PATCH] Free memory when Main::setup returns an error --- platform/windows/godot_win.cpp | 7 ++++++- platform/x11/godot_x11.cpp | 4 +++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/platform/windows/godot_win.cpp b/platform/windows/godot_win.cpp index df2d96e5162..6f1fb047068 100644 --- a/platform/windows/godot_win.cpp +++ b/platform/windows/godot_win.cpp @@ -136,8 +136,13 @@ int widechar_main(int argc, wchar_t **argv) { Error err = Main::setup(argv_utf8[0], argc - 1, &argv_utf8[1]); - if (err != OK) + if (err != OK) { + for (int i = 0; i < argc; ++i) { + delete[] argv_utf8[i]; + } + delete[] argv_utf8; return 255; + } if (Main::start()) os.run(); diff --git a/platform/x11/godot_x11.cpp b/platform/x11/godot_x11.cpp index 6f418b213fc..f02f3cb8818 100644 --- a/platform/x11/godot_x11.cpp +++ b/platform/x11/godot_x11.cpp @@ -45,8 +45,10 @@ int main(int argc, char *argv[]) { getcwd(cwd, PATH_MAX); Error err = Main::setup(argv[0], argc - 1, &argv[1]); - if (err != OK) + if (err != OK) { + free(cwd); return 255; + } if (Main::start()) os.run(); // it is actually the OS that decides how to run