- do not expose module_progdir variable

If the same global variable is used by executable that linked to ZMusic dynamic library, both definitions may clash
For example, Linux builds of GZDoom and Raze could crash on exit because of double free, std::string destructor was called twice on the same module_progdir variable
This commit is contained in:
alexey.lysiuk 2020-02-23 12:25:52 +02:00
parent b071c53aa5
commit b9d22fb358
5 changed files with 10 additions and 5 deletions

View file

@ -62,7 +62,7 @@ bool IsMPG123Present()
if (!done)
{
done = true;
auto abspath = module_progdir + "/" MPG123LIB;
auto abspath = FModule_GetProgDir() + "/" MPG123LIB;
cached_result = MPG123Module.Load({abspath.c_str(), MPG123LIB});
}
return cached_result;

View file

@ -61,7 +61,7 @@ bool IsSndFilePresent()
if (!done)
{
done = true;
auto abspath = module_progdir + "/" SNDFILELIB;
auto abspath = FModule_GetProgDir() + "/" SNDFILELIB;
cached_result = SndFileModule.Load({abspath.c_str(), SNDFILELIB});
}
return cached_result;

View file

@ -100,9 +100,14 @@ void *FModule::GetSym(const char* name)
return (void *)GetProcAddress((HMODULE)handle, name);
}
std::string module_progdir("."); // current program directory used to look up dynamic libraries. Default to something harmless in case the user didn't set it.
static std::string module_progdir("."); // current program directory used to look up dynamic libraries. Default to something harmless in case the user didn't set it.
void FModule_SetProgDir(const char* progdir)
{
module_progdir = progdir;
}
const std::string& FModule_GetProgDir()
{
return module_progdir;
}

View file

@ -230,4 +230,4 @@ public:
};
void FModule_SetProgDir(const char* progdir);
extern std::string module_progdir;
const std::string& FModule_GetProgDir();

View file

@ -615,7 +615,7 @@ void Fluid_SetupConfig(const char* patches, std::vector<std::string> &patch_path
// prepend $PROGDIR to the path.
if (strcspn(tok, ":/\\") == strlen(tok))
{
path = module_progdir + "/" + tok;
path = FModule_GetProgDir() + "/" + tok;
}
else
#endif