Fix crash on exit for shutdown