Fix segfault when closing and with -02