Because file_read allocates memory, it should be free-ed. Currently,
attempting to do so will cause a compiler warning since free does
not take const qualified pointer (because we are modifying the
memory).
Changing the return type to char * rather than const char * will
allow the caller to correctly free memory.
Also fix most of the transitive leaks I could find. e.x. strdup returns allocated memory that should be free-ed.
Last patch doesn't really fix anything but adds the malloc function attribute for the compiler but also to hint to developers that the function allocates memory that needs to be free-ed.
Because
file_read
allocates memory, it should be free-ed. Currently, attempting to do so will cause a compiler warning sincefree
does not takeconst
qualified pointer (because we are modifying the memory).Changing the return type to
char *
rather thanconst char *
will allow the caller to correctly free memory.Also fix most of the transitive leaks I could find. e.x.
strdup
returns allocated memory that should be free-ed.Last patch doesn't really fix anything but adds the
malloc
function attribute for the compiler but also to hint to developers that the function allocates memory that needs to be free-ed.