Fixed the segmentation fault during shutdown