diff --git a/include/PartitionManager/PartitionManager.hpp b/include/PartitionManager/PartitionManager.hpp index 576e18f..4d8cbf4 100644 --- a/include/PartitionManager/PartitionManager.hpp +++ b/include/PartitionManager/PartitionManager.hpp @@ -70,6 +70,16 @@ public: bool forceProcess; }; +class protector final { +private: + basic_variables *_var = nullptr; + +public: + ~protector(); + + void setVariablePtr(basic_variables *&_var); +}; + using FunctionBase = basic_function; using FunctionManager = basic_function_manager; using VariableTable = basic_variables; diff --git a/src/PartitionManager.cpp b/src/PartitionManager.cpp index f032f68..2a66b35 100644 --- a/src/PartitionManager.cpp +++ b/src/PartitionManager.cpp @@ -25,21 +25,18 @@ namespace PartitionManager { -__attribute__((constructor)) -void init() { +__attribute__((constructor)) void init() { Helper::LoggingProperties::setLogFile("/sdcard/Documents/last_pmt_logs.log"); } -__attribute__((destructor)) -void cleanup() { - delete Variables; -} - 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() - : logFile("/sdcard/Documents/last_pmt_logs.log"), onLogical(false), + : logFile(Helper::LoggingProperties::FILE), onLogical(false), quietProcess(false), verboseMode(false), viewVersion(false), forceProcess(false) { try { @@ -52,6 +49,8 @@ int Main(int argc, char **argv) { try { // try-catch start CLI::App AppMain{"Partition Manager Tool"}; + protector prot; + prot.setVariablePtr(Variables); FunctionManager FuncManager; AppMain.fallthrough(true);