I hate segfaults

This commit is contained in:
2025-03-14 23:20:46 -05:00
parent f503c3589e
commit 8ca9d9c4d9
2 changed files with 15 additions and 17 deletions

View File

@@ -41,7 +41,11 @@ void App::run() {
for(auto it = modules.begin(); it != modules.end(); it++) {
(*it)->run();
}
closeModules();
for(auto it = toClose.begin(); it != modules.end(); it++) {
unload(it);
}
toClose.clear();
}
}
@@ -77,23 +81,17 @@ void App::load(std::string lib) {
}
void App::unload(decltype(Module::self) it) {
toClose.push_back((*it)->getHandle());
std::cout << "marked handle for closure\n";
std::cout << "Attempting to delete module: " << (*it)->getName() << std::endl;
Module* m = *it;
*it = nullptr;
modules.erase(it);
std::cout << "erased iterator\n";
delete m;
void* h = (*it)->getHandle();
std::cout << "retrieved handle\nAttempting to delete module: " << (*it)->getName() << std::endl;
delete *it;
std::cout << "deleted module\n";
dlclose(h);
std::cout << "closed handle\n";
}
void App::closeModules() {
for(auto h : toClose) {
dlclose(h);
}
toClose.clear();
void App::stopModule(decltype(Module::self) it) {
toClose.push_back(*it);
modules.erase(it);
}
void App::handleArgs(const int& argc, char* argv[]) {