Re: GList and segmentation fault

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.


	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]