Starting with names5.c, replace the line at the end of main()

   // here we are lazy and do not free the list.

with a loop that calls free() on every malloc’d pointer in the list - so all malloc’d memory is free. Be careful!

You will also need to copy readlinep.h and readlinep.c along with names5.c to compile it successfully.

cp /thayerfs/courses/22fall/cosc050/workspace/activities/day10/names5.c . 
cp /thayerfs/courses/22fall/cosc050/workspace/activities/day10/readlinep.[hc] .
mygcc -o names names5.c readlinep.c

Think about what you need to free. There are two things for each node in the linked list that were dynamically allocated!

Solution

names5-free.c