Fix use after free error.