Skip to content

Commit

Permalink
fixed up leaks
Browse files Browse the repository at this point in the history
  • Loading branch information
Unreal-Dan committed Dec 1, 2023
1 parent b970bd8 commit 5007336
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
1 change: 1 addition & 0 deletions VortexEngine/VortexCLI/VortexCLI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -790,6 +790,7 @@ void VortexCLI::dumpJson() const
}
JsonPrinter printer;
printer.printJson(json);
delete json;
}

long VortexCLI::VortexCLICallbacks::checkPinHook(uint32_t pin)
Expand Down
18 changes: 18 additions & 0 deletions VortexEngine/VortexCLI/VortexJson.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -29,6 +38,15 @@ const map<string, JsonValue *> &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);
Expand Down
2 changes: 2 additions & 0 deletions VortexEngine/VortexCLI/VortexJson.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::string, JsonValue *> &getProperties() const;

Expand All @@ -43,6 +44,7 @@ class JsonObject : public JsonValue
class JsonArray : public JsonValue
{
public:
virtual ~JsonArray();
void addElement(JsonValue *value);
const std::vector<JsonValue *> &getElements() const;

Expand Down

0 comments on commit 5007336

Please sign in to comment.