fix the strange segementation error when exiting