ANNOUNCEMENT: Live Wireshark University & Allegro Packets online APAC Wireshark Training Session
July 17th, 2024 | 10:00am-11:55am SGT (UTC+8) | Online

Ethereal-dev: [Ethereal-dev] Could someone check my g_slist code please?

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

From: Richard Urwin <richard@xxxxxxxxxxxxxxx>
Date: Thu, 3 Jun 2004 19:35:24 +0100
Can somebody just check that the following code doesn't cause a memory
leak or other problems please? For example, I think that g_slist_free 
will not free the objects in the list, just the pointers to them, but 
if I'm wrong I'll end up with lists pointing to freed memory - not good 
and hard to spot.

TIA

================================
GSList *filter_list = NULL;
GSList *temp_filter_list = NULL;
GSList *removed_filter_list = NULL;

static void remove_color_filter_it(gpointer filter_arg, gpointer unused 
_U_)
{
	color_filter_t *colorf = filter_arg;
	removed_filter_list = g_slist_prepend(removed_filter_list, colorf);
}

static void globalize_color_filter_it(gpointer filter_arg, gpointer 
unused _U_)
{
	color_filter_t *colorf = filter_arg;
	filter_list = g_slist_append(filter_list, colorf);
}

void globalize_all_color_filters(void)
{
	g_slist_foreach(filter_list, remove_color_filter_it, NULL);
	g_slist_free(filter_list);
	filter_list = NULL;
	g_slist_foreach(temp_filter_list, globalize_color_filter_it, NULL);
	g_slist_free(temp_filter_list);
	temp_filter_list = NULL;
}

-- 
Richard Urwin