Re: GList and segmentation fault
- From: John Cupitt <john cupitt ng-london org uk>
- To: Mattias Persson <matper-8 student luth se>
- Cc: gtk-list gnome org
- Subject: Re: GList and segmentation fault
- Date: Thu, 19 Jul 2001 14:39:31 +0100
Mattias Persson wrote:
> GList * files = NULL;
> //nextfile is a string
> files = g_list_append(files, nextfile);
>
> later on when a GtkList is created I try to add the
> GList to it:
>
> gtk_list_append_items(list1, files);
>
> but that gives me a segmentation fault.
I guess nextfile is being freed between being added to the list and then
later being used by the clist.
Try:
files = g_list_append( files, g_strdup( nextfile ) );
Of course when you're done with "files" you now need to free all the
strings before you free "files". For example, you could do:
g_list_foreach( files, (GFunc) g_free, NULL );
g_list_free( files );
You could maybe use GSList instead of GList (if you don't need the
"previous" field).
HTH, John
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]