>>7791067 (lb)
I know a very very lot about secure idioms in C/C++. the function that you showed would work, but it does a needless copy of the string pointer and reassign.
the while loop would do the job without a function call. or just make the function a macro instead.
PS: STL is a standard library and it's well tested and leak proof by design unless you use it incorrectly.