No, you're returning a /copy/ of the TBuf that goes out of scope. It works but is not very efficient. It would be broken if the return type was either a pointer or reference to the out-of-scope stack-based buffer.
If you need a function to return dynamic strings efficiently, either allocate them in the function (allocate and return an HBufC) or take in a target buffer (a TDes& function ...



