[pr17595] Fix a use after free.

Destroying the codegen also frees the path of the created object. Copy the
path to a std::string.