Author: Stan Eisenstat
Subject: Re: [Cs223] freeing contents of nodes
Date: Friday, 20 Mar 2020, 12:31:35
> Message Posted By: Unknown
>
> The walkthrough says: Freeing a node will not free its contents! So if you
> have nodes pointing to allocated strings, you want to first free the
> allocated strings before you free the nodes (otherwise, you'll have memory
> leaks)
>
> Should we be freeing the contents of the nodes in Deque.c?
No. As stated in the specification:
5. Each value stored in a Deque is a char *, but it need not point to the
first character of a null-terminated string (e.g., it could be the NULL
pointer). Thus when adding/pushing strings returned by getline() to/on a
Deque, the strings themselves are NOT duplicated. It follows that if they
are not freed outside of the Deque ADT after a pointer is removed or
popped and returned, that storage could be lost.
--Stan-
PREV
INDEX
NEXT