he still has to keep it in scope with static and then that resource is wasted because i dont think you can free static memory unless its been dynamically allocated
Your question is too vague to answer. Can you give an example of how this function would be used? Would the function return a pointer so the data allocated within the function can be used elsewhere in the program?
A function allocating data which just remains locked in the function would be pointless. We need more info. about what you're trying to accomplish.
You could send a char *ptr as a reference argument, check for nullptr inside the function, and allocate data if it is a nullptr. When the function returns, you will have a pointer that can be used outside the function. Would be easier using classes I believe tho...