summaryrefslogtreecommitdiff
path: root/src/config/ConfigManager.cpp
diff options
context:
space:
mode:
authorTom Englund <tomenglund26@gmail.com>2025-01-28 10:20:54 +0100
committerVaxry <43317083+vaxerski@users.noreply.github.com>2025-01-28 11:19:52 +0100
commit1d3904c3e7a8b74ea83669f73ee408bd38390b11 (patch)
treecd0fefcd40ad98b3bdb191c5920766d9f9e69d90 /src/config/ConfigManager.cpp
parent529ad4eaf450e558998e7417db5db6602e7fb497 (diff)
configmgr: properly free glob memory
globfree is only freeing internally allocated resources, so also call free the on glob_t memory we allocated.
Diffstat (limited to 'src/config/ConfigManager.cpp')
-rw-r--r--src/config/ConfigManager.cpp10
1 files changed, 8 insertions, 2 deletions
diff --git a/src/config/ConfigManager.cpp b/src/config/ConfigManager.cpp
index 93289bf7..daff9285 100644
--- a/src/config/ConfigManager.cpp
+++ b/src/config/ConfigManager.cpp
@@ -2690,8 +2690,14 @@ std::optional<std::string> CConfigManager::handleSource(const std::string& comma
Debug::log(ERR, "source= path garbage");
return "source= path " + rawpath + " bogus!";
}
- std::unique_ptr<glob_t, void (*)(glob_t*)> glob_buf{new glob_t, [](glob_t* g) { globfree(g); }};
- memset(glob_buf.get(), 0, sizeof(glob_t));
+
+ std::unique_ptr<glob_t, void (*)(glob_t*)> glob_buf{static_cast<glob_t*>(calloc(1, sizeof(glob_t))), // allocate and zero-initialize
+ [](glob_t* g) {
+ if (g) {
+ globfree(g); // free internal resources allocated by glob()
+ free(g); // free the memory for the glob_t structure
+ }
+ }};
if (auto r = glob(absolutePath(rawpath, configCurrentPath).c_str(), GLOB_TILDE, nullptr, glob_buf.get()); r != 0) {
std::string err = std::format("source= globbing error: {}", r == GLOB_NOMATCH ? "found no match" : GLOB_ABORTED ? "read error" : "out of memory");