Re: g_list_remove breaks GList's next pointer
- From: Evan Martin <martine cs washington edu>
- To: gtk-app-devel-list gnome org
- Subject: Re: g_list_remove breaks GList's next pointer
- Date: Tue, 4 Feb 2003 17:56:34 -0800
On Mon, Feb 03, 2003 at 01:40:14PM -0500, gtk-list-in gnome org wrote:
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);
An empty list is simply NULL in glib.
All calls that modify lists should be of the form
list = g_list_foo(list, ...);
because if the passed-in list is empty (NULL) it could return a created
list, and if the function removes the first element, or all the elements
in the list, the head pointer will change and needs to be stored back
into "list".
In your code, you're keeping the "Programs" pointer around even after the
g_list_remove frees the memory it points to, so you can't make any
assumptions about the validity of the "next" field or anything like that.
--
Evan Martin
martine cs washington edu
http://neugierig.org
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]