fix segfault on exit