Fix a NULL pointer dereference during shutdown