Re: Why there's still ONE element left after g_slist_free () ?

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

 



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@xxxxxxxxx
http://mail.gnome.org/mailman/listinfo/gtk-list

_______________________________________________
gtk-list mailing list
gtk-list@xxxxxxxxx
http://mail.gnome.org/mailman/listinfo/gtk-list

[Index of Archives]     [Touch Screen Library]     [GIMP Users]     [Gnome]     [KDE]     [Yosemite News]     [Steve's Art]

  Powered by Linux