Re: Why there's still ONE element left after g_slist_free () ?
- From: Szilard Pfeiffer <szilard pfeiffer gmail com>
- To: PenT <pentie gmail com>
- Cc: gtk-list gnome org
- Subject: Re: Why there's still ONE element left after g_slist_free () ?
- Date: Wed, 13 May 2009 10:22:33 +0200
If you give a pointer to g_slist_length() which is not null the result
must be at least 1, because only the null value shows the end of the
list. The g_slist_free function does not set it's parameter to null (as
it can not do it) so your GSList * variable after the function call
points to a freed (maybe reallocated) memory segment. Depending on the
content of the pointed memory (especially the next member of the GSList
struct) the return value of the g_slist_length will be 1 or greater. The
surprise is the result not a segmentation fault. :)
PenT wrote:
I created a GSList and then free it using g_slist_free (), then I call
g_slist_length() and it return 1, surprising!
I thought after g_slist_free (), the GSList should be empty(NULL), why
still 1 left?
------------------------------------------------------------------------
_______________________________________________
gtk-list mailing list
gtk-list gnome org
http://mail.gnome.org/mailman/listinfo/gtk-list
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]