Suppose that I set a pointer in order to have a string, eg:
char *string = NULL;
size_t size = 0;
getline(&string, &size, stdin);
Is necessary to do a free(string)
before end the program?
As I could see in man, getline calls to malloc()
and I have supposed it.
To ensure your software doesn't have any memory leaks, yes, you should call free
for any memory that you have allocated dynamically.
Memory will be reclaimed by the OS when the process terminates, and so it doesn't matter much unless you are running low on available memory. However, using free
to release memory is very important if you're writing software that will run in the background, such as a daemon process.
It is recommended (almost universally) that the Right Way (tm) is to free
your memory and not to rely on the OS to reclaim that space.