Fix segmentation fault during shutdown.