core: at shutdown, first call the destroy module functions then free module exports structure
- some modules may need access to other modules at shut down
- reported by Juha Heinanen
(cherry picked from commit 2396dde7230e04f853e6936cfff9059661c55635)