There is a misconception in your thinking, perhaps you lack a better understanding of stack and < in> heap .
If the information is in stack you really can not trust it to be there when the function is finished. But you rarely create a pointer to the stack.
But if it is allocated in heap , you can return a pointer to this allocated area with no problems. The area remains available even when the function is finished. This is the main reason to use heap .
You are even correct in your thinking from the point of view of code organization. The most correct is the function that needs an information to allocate the necessary memory for the object, to pass this to the function that will fill this object and then when to return it to release this memory.
Nothing prevents you from allocating a function that will fill and return, but becomes asymmetric because it is responsible for allocating and does not release (nor could in this case). This gives rise to errors. Well-built functions require consumers to deliver the memory that is already in the loop. Even if it needs a reallocation within it, this is less problematic.
So from the technical point of view you can do as you asked, but any good programmer would do the way you are thinking. You're correct.