Search code examples
apacheapache-modules

Notify module to cleanup before FreeLibrary of Module DLL


Does Apache Web server notify a module in any way that it is about to unload the module?

On Windows I am looking for a way to do some cleanup inside a Module DLL before the DLL is unloaded because of the possibilities of thread deadlock inside DLLMain() DLLMain handles both process detachment as well as thread detachment and as such you cannot wait for a thread when the process is detached.


Solution

  • I came upon Apache's apr_pool_cleanup and the companion apr_pool_cleanup_register procedure which registers a hook into the the cleanup. This will allow you to do some proper cleanup before the DLL is unloaded