need help freeing a linked list
So, in general, freeing a linked list is pretty straight forward. my freeing function looks like this:
However I want to optimise my code some, and don't want to have separate malloc calls for every node in a given list. However, the way the program runs, I may have a couple separate nodes followed by a bunch of nodes that are stored in a contiguous memory block that was malloced all at once. The problem is, of course, that the free_chain function will try to free each node individually, even if they were malloced as one chunk, and thus run into a double free problem. How do I get around this?
typedef struct node
struct node *next;
struct node *prev;
void free_chain(node* hostage)
Thanks so much!