Fix use after free.
Fix bad free.
Avoid "Branch condition evaluates to a garbage value"