Fix a crash or random memory leak when reseting saved environment variable in test_se...
authorLoic Blot <loic.blot@unix-experience.fr>
Fri, 16 Mar 2018 18:34:41 +0000 (19:34 +0100)
committerLoic Blot <loic.blot@unix-experience.fr>
Fri, 16 Mar 2018 18:34:41 +0000 (19:34 +0100)
src/unittest/test_servermodmanager.cpp

index cb43babf939f26ab5874da746679b80d9cf77246..72ac7c6bf3a3e1f76df6db2120427e885206b07c 100644 (file)
@@ -71,11 +71,15 @@ void TestServerModManager::runTests(IGameDef *gamedef)
 #ifdef WIN32
        {
                std::string subgame_path("MINETEST_SUBGAME_PATH=");
-               subgame_path.append(saved_env_mt_subgame_path);
+               if (saved_env_mt_subgame_path)
+                       subgame_path.append(saved_env_mt_subgame_path);
                _putenv(subgame_path.c_str());
        }
 #else
-       setenv("MINETEST_SUBGAME_PATH", saved_env_mt_subgame_path, 1);
+       if (saved_env_mt_subgame_path)
+               setenv("MINETEST_SUBGAME_PATH", saved_env_mt_subgame_path, 1);
+       else
+               unsetenv("MINETEST_SUBGAME_PATH");
 #endif
 }