From d00eee88d610657ddc997aed82e0faffa7e91909 Mon Sep 17 00:00:00 2001 From: marcelb Date: Sat, 1 Feb 2025 21:49:58 +0100 Subject: [PATCH] Memory leak fix --- example/config.cfg | 1 + src/config.cpp | 5 ++++- test/test.cpp | 3 ++- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/example/config.cfg b/example/config.cfg index 60f0602..ccc6e40 100644 --- a/example/config.cfg +++ b/example/config.cfg @@ -10,3 +10,4 @@ DinioServer1Port=5000; DinioServer2Port=4048; DinioGetIPURL=http://lab-it.ddns.net/getip/index.php; #ovo ide na više A recorda i više servera pod istim domenom # DinioGetIPURL2=http://ns-hl.ddns.net/getip/index.php; +Baba2=Janja; diff --git a/src/config.cpp b/src/config.cpp index e464be5..35498b7 100644 --- a/src/config.cpp +++ b/src/config.cpp @@ -14,7 +14,10 @@ marcelb::config::config(const string _configFilePath, const vector _nece string marcelb::config::operator[](const string& key) { - return element[key]; + if (element.count(key)) { + return element[key]; + } + return ""; } void marcelb::config::update(const string& key, const string& value) { diff --git a/test/test.cpp b/test/test.cpp index dad8aab..49de224 100644 --- a/test/test.cpp +++ b/test/test.cpp @@ -1,5 +1,6 @@ #include #include "../lib/config.hpp" +#include using namespace std; using namespace marcelb; @@ -12,6 +13,6 @@ int main() { mycfg.update("Baba2", "Janja"); cout << mycfg["Baba"]; - + sleep(10000); return 0; } \ No newline at end of file