fix segfault during cleanup