From 735e483d9fc1d5072b8ec9ccf122f97339e7d6c2 Mon Sep 17 00:00:00 2001 From: Johannes Lorenz <1042576+JohannesLorenz@users.noreply.github.com> Date: Sun, 4 Aug 2024 16:21:34 +0200 Subject: [PATCH] Fix memleaks in help/version (#7423) * Fix memleaks in help/version These memory leaks caused help and version to crash at the end, due to rpmalloc's memleak detection. --- src/core/main.cpp | 106 +++++++++++++++++++++++----------------------- 1 file changed, 52 insertions(+), 54 deletions(-) diff --git a/src/core/main.cpp b/src/core/main.cpp index b970997eff5..395f58c3d1c 100644 --- a/src/core/main.cpp +++ b/src/core/main.cpp @@ -257,6 +257,57 @@ int main( int argc, char * * argv ) { using namespace lmms; + bool coreOnly = false; + bool fullscreen = true; + bool exitAfterImport = false; + bool allowRoot = false; + bool renderLoop = false; + bool renderTracks = false; + QString fileToLoad, fileToImport, renderOut, profilerOutputFile, configFile; + + // first of two command-line parsing stages + for (int i = 1; i < argc; ++i) + { + QString arg = argv[i]; + + if (arg == "--help" || arg == "-h") + { + printHelp(); + return EXIT_SUCCESS; + } + else if (arg == "--version" || arg == "-v") + { + printVersion(argv[0]); + return EXIT_SUCCESS; + } + else if (arg == "render" || arg == "--render" || arg == "-r" ) + { + coreOnly = true; + } + else if (arg == "rendertracks" || arg == "--rendertracks") + { + coreOnly = true; + renderTracks = true; + } + else if (arg == "--allowroot") + { + allowRoot = true; + } + else if (arg == "--geometry" || arg == "-geometry") + { + if (arg == "--geometry") + { + // Delete the first "-" so Qt recognize the option + strcpy(argv[i], "-geometry"); + } + // option -geometry is filtered by Qt later, + // so we need to check its presence now to + // determine, if the application should run in + // fullscreen mode (default, no -geometry given). + fullscreen = false; + } + } + #ifdef LMMS_DEBUG_FPE // Enable exceptions for certain floating point results // FE_UNDERFLOW is disabled for the time being @@ -314,49 +365,6 @@ int main( int argc, char * * argv ) disable_denormals(); - bool coreOnly = false; - bool fullscreen = true; - bool exitAfterImport = false; - bool allowRoot = false; - bool renderLoop = false; - bool renderTracks = false; - QString fileToLoad, fileToImport, renderOut, profilerOutputFile, configFile; - - // first of two command-line parsing stages - for( int i = 1; i < argc; ++i ) - { - QString arg = argv[i]; - - if( arg == "--help" || arg == "-h" || - arg == "--version" || arg == "-v" || - arg == "render" || arg == "--render" || arg == "-r" ) - { - coreOnly = true; - } - else if( arg == "rendertracks" || arg == "--rendertracks" ) - { - coreOnly = true; - renderTracks = true; - } - else if( arg == "--allowroot" ) - { - allowRoot = true; - } - else if( arg == "--geometry" || arg == "-geometry") - { - if( arg == "--geometry" ) - { - // Delete the first "-" so Qt recognize the option - strcpy(argv[i], "-geometry"); - } - // option -geometry is filtered by Qt later, - // so we need to check its presence now to - // determine, if the application should run in - // fullscreen mode (default, no -geometry given). - fullscreen = false; - } - } - #if !defined(LMMS_BUILD_WIN32) && !defined(LMMS_BUILD_HAIKU) if ( ( getuid() == 0 || geteuid() == 0 ) && !allowRoot ) { @@ -382,17 +390,7 @@ int main( int argc, char * * argv ) { QString arg = argv[i]; - if( arg == "--version" || arg == "-v" ) - { - printVersion( argv[0] ); - return EXIT_SUCCESS; - } - else if( arg == "--help" || arg == "-h" ) - { - printHelp(); - return EXIT_SUCCESS; - } - else if( arg == "upgrade" || arg == "--upgrade" || arg == "-u") + if (arg == "upgrade" || arg == "--upgrade" || arg == "-u") { ++i;