Similar to e0ff7731e0.
Noticed a data race when working on blender/blender!130543, which calls
this function from a thread. Make this thread safe by avoiding returning
of static memory, instead use an optional `std::string`.
Pull Request: https://projects.blender.org/blender/blender/pulls/141083