You must free each element of your list individually. Each slice of memory that has been allocated by malloc
must be freed with free
.
Instead of calling free(a)
at the end of your program, call freenodes()
.
void freenodes()
{
struct node *a;
a = start;
while(a != NULL)
{
struct node *freenode = a ;
a = a->next;
free(freenode) ;
}
}