Fix pointer used after free