fixed segfault when exiting