From 5007336acefba596ae8c2bb651f59d55f15aeabd Mon Sep 17 00:00:00 2001 From: Dan Date: Fri, 1 Dec 2023 02:09:04 -0800 Subject: [PATCH] fixed up leaks --- VortexEngine/VortexCLI/VortexCLI.cpp | 1 + VortexEngine/VortexCLI/VortexJson.cpp | 18 ++++++++++++++++++ VortexEngine/VortexCLI/VortexJson.h | 2 ++ 3 files changed, 21 insertions(+) diff --git a/VortexEngine/VortexCLI/VortexCLI.cpp b/VortexEngine/VortexCLI/VortexCLI.cpp index 4b014be72e..e94b0094f0 100644 --- a/VortexEngine/VortexCLI/VortexCLI.cpp +++ b/VortexEngine/VortexCLI/VortexCLI.cpp @@ -790,6 +790,7 @@ void VortexCLI::dumpJson() const } JsonPrinter printer; printer.printJson(json); + delete json; } long VortexCLI::VortexCLICallbacks::checkPinHook(uint32_t pin) diff --git a/VortexEngine/VortexCLI/VortexJson.cpp b/VortexEngine/VortexCLI/VortexJson.cpp index 6ebcf55348..6d1427f3dd 100644 --- a/VortexEngine/VortexCLI/VortexJson.cpp +++ b/VortexEngine/VortexCLI/VortexJson.cpp @@ -19,6 +19,15 @@ const string &JsonString::getValue() const return value; } +JsonObject::~JsonObject() +{ + // Cleanup properties + for (auto& pair : properties) { + delete pair.second; // Release memory occupied by JsonValue objects + } + properties.clear(); // Clear the map +} + void JsonObject::addProperty(const string &key, JsonValue *value) { properties[key] = value; @@ -29,6 +38,15 @@ const map &JsonObject::getProperties() const return properties; } +JsonArray::~JsonArray() +{ + // Cleanup properties + for (auto& el : elements) { + delete el; // Release memory occupied by JsonValue objects + } + elements.clear(); // Clear the map +} + void JsonArray::addElement(JsonValue *value) { elements.push_back(value); diff --git a/VortexEngine/VortexCLI/VortexJson.h b/VortexEngine/VortexCLI/VortexJson.h index 0dfcf05dbd..06fe985923 100644 --- a/VortexEngine/VortexCLI/VortexJson.h +++ b/VortexEngine/VortexCLI/VortexJson.h @@ -33,6 +33,7 @@ class JsonString : public JsonValue class JsonObject : public JsonValue { public: + virtual ~JsonObject(); void addProperty(const std::string &key, JsonValue *value); const std::map &getProperties() const; @@ -43,6 +44,7 @@ class JsonObject : public JsonValue class JsonArray : public JsonValue { public: + virtual ~JsonArray(); void addElement(JsonValue *value); const std::vector &getElements() const;