I would always protect your own function to free the memory that your library returns if you do not return something trivial, such as a string.
The reason for this is that if you change the structure of what you return, so that there will no longer be free (because you add objects to the allocated memory that should be freed), the clients will not need to change their code ; you can simply modify an existing free function.
Thus, the presence of your free function isolates clients from the structure of objects returned by your library, leaving the ability to change the structure of your objects without affecting clients.
Martin broadhurst
source share