From 030740ee345ccaa638c1cc4d4013936128fa2adf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ed=C3=AAnis=20Freindorfer=20Azevedo?= Date: Wed, 3 Jul 2019 22:33:43 -0300 Subject: [PATCH] Fix some memory leak. --- src/common/ConfigManager.cpp | 10 +++++----- src/sdl/SDL.cpp | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/common/ConfigManager.cpp b/src/common/ConfigManager.cpp index 583b2445..9cf829fb 100644 --- a/src/common/ConfigManager.cpp +++ b/src/common/ConfigManager.cpp @@ -663,12 +663,12 @@ const char* FindConfigFile(const char *name) struct stat s; std::string homeDirTmp = get_xdg_user_config_home() + DOT_DIR; - homeDir = strdup(homeDirTmp.c_str()); - if (stat(homeDir, &s) == -1 || !S_ISDIR(s.st_mode)) - mkdir(homeDir, 0755); + char *fullDir = (char *)homeDirTmp.c_str(); + if (stat(fullDir, &s) == -1 || !S_ISDIR(s.st_mode)) + mkdir(fullDir, 0755); - if (homeDir) { - sprintf(path, "%s%c%s", homeDir, FILE_SEP, name); + if (fullDir) { + sprintf(path, "%s%c%s", fullDir, FILE_SEP, name); if (FileExists(path)) { return path; diff --git a/src/sdl/SDL.cpp b/src/sdl/SDL.cpp index 86d86201..48cfc24b 100644 --- a/src/sdl/SDL.cpp +++ b/src/sdl/SDL.cpp @@ -369,7 +369,7 @@ FILE* sdlFindFile(const char* name) return f; } - if (homeDir) { + if (homeDataDir) { fprintf(stdout, "Searching home directory: %s\n", homeDataDir); sprintf(path, "%s%c%s", homeDataDir, FILE_SEP, name); f = fopen(path, "r");