From ac7dd20a38c16fac91bb8d82700d1c03dc9d266e Mon Sep 17 00:00:00 2001 From: "Azamat H. Hackimov" Date: Sun, 29 Sep 2024 16:53:54 +0300 Subject: [PATCH] Fix memory leak from unpaired SDL_GetPrefPath() --- linux/lnxdata.cpp | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/linux/lnxdata.cpp b/linux/lnxdata.cpp index 24151b0c..ea79dd86 100644 --- a/linux/lnxdata.cpp +++ b/linux/lnxdata.cpp @@ -42,8 +42,9 @@ */ #include -#include -#include +#include + +#include #if defined(POSIX) #include @@ -53,11 +54,8 @@ #include #endif -#include - #include "appdatabase.h" #include "linux/lnxdatabase.h" -#include "pserror.h" #include "log.h" #include "pserror.h" #include "registry.h" @@ -70,20 +68,17 @@ oeLnxAppDatabase::oeLnxAppDatabase() { // Open up the database file, for reading, read in all data and keep it in memory // then close the database - char const* prefPath = SDL_GetPrefPath("Outrage Entertainment", "Descent 3"); - if (prefPath == NULL) { - fprintf(stderr, "ERROR: Couldn't find preference directory!\n"); + const char* prefPath = SDL_GetPrefPath("Outrage Entertainment", "Descent 3"); + if (prefPath == nullptr) { + LOG_FATAL << "Couldn't find preference directory!"; exit(43); } + std::filesystem::path fileName = std::filesystem::path(prefPath) / REGISTRY_FILENAME; + SDL_free((void *)prefPath); - const size_t fileLen = strlen(prefPath) + strlen(REGISTRY_FILENAME) + 2; - char* fileName = new char[fileLen]; - snprintf(fileName, fileLen, "%s/%s", prefPath, REGISTRY_FILENAME); - - database = new CRegistry(fileName); + database = new CRegistry(fileName.u8string().c_str()); database->Import(); create_record("Version"); - delete [] fileName; } oeLnxAppDatabase::oeLnxAppDatabase(oeLnxAppDatabase *parent) {