freeing list that gets nodes from block
ok, lets say i have a function that gets nodes for a linked list from a malloc'ed/calloc'ed block of structs. lets also say that the function exhaust several blocks. after im finished doing whatever with the list, how do i free all the nodes. i dont think i could just traverse the list freeing each node because id end up freeing addresses that have already been freed (i think). i thought maybe i could either store the beginning address of each block allocated on a stack then traverse through that or maybe i could free the first node in the list, go down BLOCKSIZE nodes, free and repeat until end of list but im not sure which would be the best way to do it. im not even sure if thats the way it should be done.
id really appreciate it if you guys could help me out with this. thanks in advance.