Fix potential double free when unloading a module.