Fixed memory leaks when unloading all modules