Will this leak memory?

Specifically, I.11: Never transfer ownership by a raw pointer (T*) or reference (T&). I.e. never return malloc'ed memory using a raw pointer.

I would return a String if dynamic allocation is absolutely necessary (or if it's on a non-embedded system and I'm lazy).
In this case, and in general if you don't need dynamic allocation, and if you are not in a multithreaded environment and the function doesn't have to be reentrant (e.g. never called in an ISR), I'd probably just use a static local char array and return a pointer to it.

1 Like