mirror of
https://github.com/ZDoom/ZMusic.git
synced 2025-01-18 06:11:46 +00:00
- 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:
parent
b071c53aa5
commit
b9d22fb358
5 changed files with 10 additions and 5 deletions
|
@ -62,7 +62,7 @@ bool IsMPG123Present()
|
||||||
if (!done)
|
if (!done)
|
||||||
{
|
{
|
||||||
done = true;
|
done = true;
|
||||||
auto abspath = module_progdir + "/" MPG123LIB;
|
auto abspath = FModule_GetProgDir() + "/" MPG123LIB;
|
||||||
cached_result = MPG123Module.Load({abspath.c_str(), MPG123LIB});
|
cached_result = MPG123Module.Load({abspath.c_str(), MPG123LIB});
|
||||||
}
|
}
|
||||||
return cached_result;
|
return cached_result;
|
||||||
|
|
|
@ -61,7 +61,7 @@ bool IsSndFilePresent()
|
||||||
if (!done)
|
if (!done)
|
||||||
{
|
{
|
||||||
done = true;
|
done = true;
|
||||||
auto abspath = module_progdir + "/" SNDFILELIB;
|
auto abspath = FModule_GetProgDir() + "/" SNDFILELIB;
|
||||||
cached_result = SndFileModule.Load({abspath.c_str(), SNDFILELIB});
|
cached_result = SndFileModule.Load({abspath.c_str(), SNDFILELIB});
|
||||||
}
|
}
|
||||||
return cached_result;
|
return cached_result;
|
||||||
|
|
|
@ -100,9 +100,14 @@ void *FModule::GetSym(const char* name)
|
||||||
return (void *)GetProcAddress((HMODULE)handle, 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)
|
void FModule_SetProgDir(const char* progdir)
|
||||||
{
|
{
|
||||||
module_progdir = progdir;
|
module_progdir = progdir;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const std::string& FModule_GetProgDir()
|
||||||
|
{
|
||||||
|
return module_progdir;
|
||||||
|
}
|
||||||
|
|
|
@ -230,4 +230,4 @@ public:
|
||||||
};
|
};
|
||||||
|
|
||||||
void FModule_SetProgDir(const char* progdir);
|
void FModule_SetProgDir(const char* progdir);
|
||||||
extern std::string module_progdir;
|
const std::string& FModule_GetProgDir();
|
||||||
|
|
|
@ -615,7 +615,7 @@ void Fluid_SetupConfig(const char* patches, std::vector<std::string> &patch_path
|
||||||
// prepend $PROGDIR to the path.
|
// prepend $PROGDIR to the path.
|
||||||
if (strcspn(tok, ":/\\") == strlen(tok))
|
if (strcspn(tok, ":/\\") == strlen(tok))
|
||||||
{
|
{
|
||||||
path = module_progdir + "/" + tok;
|
path = FModule_GetProgDir() + "/" + tok;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in a new issue