There are two different API implementation to get data.
// (*1) return, length of data remained.
get_data(char* buffer /*in/out*/, int buffer_size/*in*/);
// (*2) caller should free memory of (*data).
get_data(char** data/*out*/, int* len/*out*/);
This is very clear and safe, but inefficient in performance point of view and difficult to implement.
And, the one who allocates memory, frees it too. (very reasonable. So, there is less risk of memory leak.)
(*2) : contrary to (*1)
Which one is better? In general, (*1) is recommended.
In terms of memory allocation/free, if possible, the one who allocates should free it. In case of this is not reasonable, at least, allocation-free-pair should be easy to track!