Skip to content
Permalink
Browse files

Change where the config dir is created.

On Windows, if there is a `vbam.ini` where the exe is, we should not
create the configuration directory `%LOCALAPPDATA%\visualboyadvance-m`.
  • Loading branch information
denisfa authored and rkitover committed May 30, 2019
1 parent 3490620 commit bf6f2d4ac276dd21c6a837ec3795d7a03d3d0bdd
Showing with 6 additions and 12 deletions.
  1. +6 −12 src/common/ConfigManager.cpp
@@ -659,6 +659,12 @@ const char* FindConfigFile(const char *name)
return name;
}

struct stat s;
std::string homeDirTmp = get_xdg_user_config_home() + DOT_DIR;
homeDir = (char *)homeDirTmp.c_str();
if (stat(homeDir, &s) == -1 || !S_ISDIR(s.st_mode))
mkdir(homeDir, 0755);

if (homeDir) {
sprintf(path, "%s%c%s", homeDir, FILE_SEP, name);
if (FileExists(path))
@@ -730,12 +736,6 @@ const char* FindConfigFile(const char *name)

void LoadConfigFile()
{
struct stat s;
std::string homeDirTmp = get_xdg_user_config_home() + DOT_DIR;
homeDir = (char *)homeDirTmp.c_str();
if (stat(homeDir, &s) == -1 || !S_ISDIR(s.st_mode))
mkdir(homeDir, 0755);

if (preferences == NULL)
{
const char* configFile = FindConfigFile("vbam.ini");
@@ -745,12 +745,6 @@ void LoadConfigFile()

void SaveConfigFile()
{
struct stat s;
std::string homeDirTmp = get_xdg_user_config_home() + DOT_DIR;
homeDir = (char *)homeDirTmp.c_str();
if (stat(homeDir, &s) == -1 || !S_ISDIR(s.st_mode))
mkdir(homeDir, 0755);

const char* configFile = FindConfigFile("vbam.ini");

if (configFile != NULL)

2 comments on commit bf6f2d4

@FredericHamel

This comment has been minimized.

Copy link

FredericHamel replied Jun 22, 2019

The global variable homeDir will contain a pointer to unallocated memory. homeDirTmp.c_str() only return a pointer to the internal buffer of the string object. When the destructor of homeDirTmp is called at the end of its scope the internal buffer is freed. Because homeDir is pointing to the internal buffer of homeDirTmp, this means that homeDir is no longer valid. The char string chould be copied using strdup or equivalent.

@rkitover

This comment has been minimized.

Copy link
Collaborator

rkitover replied Jun 23, 2019

@FredericHamel thank you for catching this, I'll add a strdup.

Please sign in to comment.
You can’t perform that action at this time.