An allocated char pointer was reassigned without being freed. Fix by replacing the error-prone combination of C strings and std::string with a complete conversion to std::string. Also change the logic a bit to allow moving the path string in some cases instead of copying it. Pull Request: https://projects.blender.org/blender/blender/pulls/118046