fix memory leak

This commit is contained in:
2025-08-15 17:22:04 +03:00
parent 7240cca537
commit 47382ebf1c
2 changed files with 17 additions and 8 deletions

View File

@@ -70,6 +70,16 @@ public:
bool forceProcess; bool forceProcess;
}; };
class protector final {
private:
basic_variables *_var = nullptr;
public:
~protector();
void setVariablePtr(basic_variables *&_var);
};
using FunctionBase = basic_function; using FunctionBase = basic_function;
using FunctionManager = basic_function_manager; using FunctionManager = basic_function_manager;
using VariableTable = basic_variables; using VariableTable = basic_variables;

View File

@@ -25,21 +25,18 @@
namespace PartitionManager { namespace PartitionManager {
__attribute__((constructor)) __attribute__((constructor)) void init() {
void init() {
Helper::LoggingProperties::setLogFile("/sdcard/Documents/last_pmt_logs.log"); Helper::LoggingProperties::setLogFile("/sdcard/Documents/last_pmt_logs.log");
} }
__attribute__((destructor))
void cleanup() {
delete Variables;
}
auto Variables = new VariableTable(); auto Variables = new VariableTable();
void protector::setVariablePtr(basic_variables *&_var) { this->_var = _var; }
protector::~protector() { delete _var; }
basic_variables::~basic_variables() { delete PartMap; } basic_variables::~basic_variables() { delete PartMap; }
basic_variables::basic_variables() basic_variables::basic_variables()
: logFile("/sdcard/Documents/last_pmt_logs.log"), onLogical(false), : logFile(Helper::LoggingProperties::FILE), onLogical(false),
quietProcess(false), verboseMode(false), viewVersion(false), quietProcess(false), verboseMode(false), viewVersion(false),
forceProcess(false) { forceProcess(false) {
try { try {
@@ -52,6 +49,8 @@ int Main(int argc, char **argv) {
try { try {
// try-catch start // try-catch start
CLI::App AppMain{"Partition Manager Tool"}; CLI::App AppMain{"Partition Manager Tool"};
protector prot;
prot.setVariablePtr(Variables);
FunctionManager FuncManager; FunctionManager FuncManager;
AppMain.fallthrough(true); AppMain.fallthrough(true);