I have a very simple linked list:
Code:
typedef struct VECLIST {
	var x;
	var y;
	var z;
	struct VECLIST* next;
} VECLIST;

And I allocate it with VECLIST* first = sys_malloc(sizeof(VECLIST));. It gets filled up to an arbitrary length, then I'm done with it, and I want to free it.

I would've thought I had to free each member of the list, but if I do so like this:
Code:
current = first;
while (current != NULL) {
	iterator = current;
	current = current->next;
	sys_free(iterator);
}

...where current, first, and iterator are each of type VECLIST*, I get an error saying "Invalid pointer freed". If I only free the first member of the list, nothing wrong happens at all, but I don't know what's getting freed. When I free the first and second member of the list I get the error again: "Invalid pointer freed". This appears to indicate that by freeing the first member I free the whole list, but that just doesn't seem right to me.

In summary: Am I trying to use sys_free incorrectly? What exactly is it meant to do? I don't think it should free the whole list in one instruction (though it's manageable if it does, as I can set pointers to NULL first before freeing an element that shouldn't take others with it). Can anyone with better understanding about this please shed some more light on this?

Thanks,

Jibb


Formerly known as JulzMighty.
I made KarBOOM!