Re: GSList and g_filename_from_uri free memory problem



On Thu, Feb 23, 2006 at 09:22:30AM +0100, Colossus wrote:

gchar **array = NULL;:
array = gtk_selection_data_get_uris ( data );
while (array[len])
{
       filename = g_filename_from_uri ( array[len] , NULL, NULL );
       Files_to_Add = g_slist_prepend ( Files_to_Add , filename );
       g_free (filename);
       len++;
}

The problem is that when I free filename the GSList data becames 
corrupted, but the docs says that g_filename_from_uri returns 
allocated memory, so what can I do ? Once I put filename in the GSList 
I don't need it anymore.

I suppose you do need something when you store it to
a GSList.  What is the point of storing pointers to freed
memory to a GSList?

Is filename freed when I call g_slist_free ?

You have to free it yourself before freeing the list or
individual elements.

GSList can store some untyped pointers.  It has no idea of
what they point to (or if they are real pointers at all),
therefore it cannot make copies of the data, cannot free
them, etc.  It just stores some untyped pointers.

Yeti


--
That's enough.



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