Fix segfault on close