Re: g_list_remove breaks GList's next pointer



gtk-list-in gnome org wrote:
I have an application I am writing here using glib 2.2.0.

In this application, I create a GList.  I then add a single item to
the list and then remove it.  However, after removing it, the
GList->next pointer seems to get pointed to an empty list element as
can been seen with this gdb analysis:

Breakpoint 1, freeProgram (data=0x8068658, userdata=0x0) at schedule.c:174
174             g_list_remove(Programs, program);

This line should read:

Programs = g_list_remove(Programs,program);

Any g_list (or g_slist) function that might modifiy the structure of the list (which is nearly all of them, except the foreach ones, I think), returns the (possibly new) start of the list. In this case, since g_list_remove() does modify the structure of the list, you need to reassign Programs to the new head of the list (it should be NULL now, ie: a GList with no elements).

Hope this helps


Or maybe I am not quite understanding GLists.

b.



--
-charlie




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]