move erase to after dlclose

This commit is contained in:
2025-03-15 14:24:43 -05:00
parent b58b071f4c
commit 00563c74a7
2 changed files with 4 additions and 15 deletions

View File

@@ -11,6 +11,4 @@ Print::~Print() {
void Print::run() { void Print::run() {
std::cout << "Print lib loaded and run!\n"; std::cout << "Print lib loaded and run!\n";
app.stopModule(self); app.stopModule(self);
//app.end();
std::cout << "app.stopModule() called\n";
} }

View File

@@ -22,13 +22,9 @@ App::~App() {
std::cout << "\nExiting...\n"; std::cout << "\nExiting...\n";
for(auto it = modules.begin(); it != modules.end(); it++) { for(auto it = modules.begin(); it != modules.end(); it++) {
void* handle = (*it)->getHandle(); void* handle = (*it)->getHandle();
std::cout << "retrieved handle\n";
delete *it; delete *it;
std::cout << "deleted module\n";
dlclose(handle); dlclose(handle);
std::cout << "closed lib\n";
it = modules.erase(it); it = modules.erase(it);
std::cout << "erased list node\n";
} }
} }
@@ -80,22 +76,17 @@ void App::load(std::string lib) {
modules.end()++; modules.end()++;
} }
void App::unload(decltype(Module::self) it) { void App::unload(std::list<Module*>::iterator it) {
void* h = (*it)->getHandle(); void* h = (*it)->getHandle();
std::cout << "retrieved handle\n";
modules.erase((*it)->self);
std::cout << "erased module.self";
std::cout << "Attempting to delete module: " << (*it)->getName() << std::endl;
delete *it; delete *it;
std::cout << "deleted module\n";
dlclose(h); dlclose(h);
std::cout << "successfully dlclosed\n";
modules.erase((*it)->self);
} }
void App::stopModule(decltype(Module::self) it) { void App::stopModule(std::list<Module*>::iterator it) {
toClose.push_back(*it); toClose.push_back(*it);
} }