Author: Stan Eisenstat
Subject: Re: [Cs223] free(line)
Date: Thursday, 19 Mar 2020, 23:14:13
> Message Posted By: Unknown
>
> In example.c, why is free(line) required? Wasn't it mentioned in lecture
> that free() should only be used when the memory was allocated through
> malloc/realloc/calloc? These weren't used in example.c.
As state on the man page for getline (see "man
getline"):
If *lineptr is set to NULL and *n is set 0 before the
call, then getline() will allocate a buffer for
storing the line. This buffer should be freed by the
user program even if getline() failed.
--Stan-
PREV
INDEX
NEXT