Fixed use after free.
discovered by Lyon Yang Shiwei