Huge thanks to our Platinum Members Endace and LiveAction,
and our Silver Member Veeam, for supporting the Wireshark Foundation and project.

Ethereal-dev: Re: [Ethereal-dev] patch to pcap-util.c

Note: This archive is from the project's previous web site, ethereal.com. This list is no longer active.

From: Guy Harris <guy@xxxxxxxxxxxx>
Date: Sun, 6 Jul 2003 14:04:31 -0700
On Sun, Jul 06, 2003 at 01:59:28PM -0400, Nathan Jennings wrote:
> Well, the documentation also says, "The removed element's prev and next 
> links are set to NULL, so that it becomes a self-contained list with one 
> element." I observed this when I ran across it in the debugger. When the 
> function is called on the list, the prev and next links are set to NULL, 
> so there's only one element to be freed... there's nothing else (NULL) 
> to iterate through.

Yes, but...

..."g_list_remove_link()" returns the new start of the GList, without
the element, and the loop was doing

        while (if_list != NULL) {
                g_free(if_list->data);
                if_list = g_list_remove_link(if_list, if_list);
        }

which amounts to

	while (there's anything in the list) {
		g_free(the data for the first element in the loop);
		remove that element and set the list to what remains in
		    the list - *not* to the remaining element;
	}

so, unless either

	1) the documentation for "g_list_remove_link()" is incorrect;

	2) "Returns: the new start of the GList, without the element."
	   doesn't mean what it sounds to me as if it should mean;

	3) the implementation is buggy;

the loop *will* traverse all elements in the list, as it's not using the
prev or next links.