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: Nathan Jennings <njen@xxxxxxxxxxxxx>
Date: Sun, 06 Jul 2003 13:59:28 -0400
Guy Harris wrote:
On Fri, Jul 04, 2003 at 10:15:43AM -0400, Nathan Jennings wrote:

I think I found a memory leak in pcap-util's free_interface_list(). I think g_list_remove_link() is the wrong function to use here.


Yes, but...


It isolates a list element from the current list. So, only one element was being freed each time it was called.


...the consequence isn't that only one element gets freed, the
consequence is that all the data items attached to the list elements get
freed (as we iterate on what's left of the list after removing the
element), but *NONE* of the list elements themselves get freed (because
"g_list_remove_link()", as its documentation says, "Removes an element
from a GList, *without* freeing the element".


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.

Not to "split hairs" here though, I thought it was worth mentioning since it may be used incorrectly in other places.

-Nathan