fix segfault on multiple close()