Stack Exchange network consists of 183 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.
Normally, yes, you allocate the pointer into the function and return it. However, since it becomes the caller's responsibility to free it, you have to clearly document that.
Ok, I re-read the code and indeed, it works as you dereference your pointer from the calling side. But then, just return your structures by value, not reference. I'll fix my answer...