Fix segfault with app destruction