Ethereal-dev: [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: Fri, 04 Jul 2003 10:15:43 -0400
Hello,

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. It isolates a list element from the current list. So, only one element was being freed each time it was called. See attached patch.

-Nathan
Index: pcap-util.c
===================================================================
RCS file: /cvsroot/ethereal/pcap-util.c,v
retrieving revision 1.13
diff -u -r1.13 pcap-util.c
--- pcap-util.c	13 Jun 2003 02:37:42 -0000	1.13
+++ pcap-util.c	1 Jul 2003 18:21:04 -0000
@@ -519,10 +519,8 @@
 void
 free_interface_list(GList *if_list)
 {
-	while (if_list != NULL) {
-		g_free(if_list->data);
-		if_list = g_list_remove_link(if_list, if_list);
-	}
+	g_list_foreach(if_list, free_if_cb, NULL);
+	g_list_free(if_list);
 }
 
 #endif /* HAVE_LIBPCAP */