Fix use after free

and free the strduped string