an attempt at cleaning up frees

there are now three types of free
functions, free_node, free_list(which
iterates over all elements in a list
and calls free_node on them), and
free_buffer. these should clear up
all the random frees in the code and
ensure NULL checks for each as well.