mirror of
https://github.com/anope/anope.git
synced 2026-06-24 18:26:37 +02:00
Revert "Do not use new/delete to allocate modules, allows modules to always destruct properly and automatically"
This does not work as expected, it causes objects allocated by modules to be freed by the operating system when
the module is unloaded, giving no chance to the module to deallocate it itself.
This reverts commit 05e6815d91.
This commit is contained in:
+16
-2
@@ -255,8 +255,22 @@ void ModuleManager::DeleteModule(Module *m)
|
||||
ano_module_t handle = m->handle;
|
||||
Anope::string filename = m->filename;
|
||||
|
||||
if (handle && dlclose(handle))
|
||||
Log() << ano_moderr();
|
||||
ano_modclearerr();
|
||||
void (*destroy_func)(Module *m) = function_cast<void (*)(Module *)>(dlsym(m->handle, "AnopeFini"));
|
||||
const char *err = ano_moderr();
|
||||
if (!destroy_func && err && *err)
|
||||
{
|
||||
Log() << "No destroy function found, chancing delete...";
|
||||
delete m; /* we just have to chance they haven't overwrote the delete operator then... */
|
||||
}
|
||||
else
|
||||
destroy_func(m); /* Let the module delete it self, just in case */
|
||||
|
||||
if (handle)
|
||||
{
|
||||
if (dlclose(handle))
|
||||
Log() << ano_moderr();
|
||||
}
|
||||
|
||||
if (!filename.empty())
|
||||
DeleteFile(filename.c_str());
|
||||
|
||||
Reference in New Issue
Block a user