GSList and g_filename_from_uri free memory problem

2006-02-23 Thread Colossus
Hi, I have this code: 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

Re: GSList and g_filename_from_uri free memory problem

2006-02-23 Thread David Necas (Yeti)
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 );

Re: GSList and g_filename_from_uri free memory problem

2006-02-23 Thread Colossus
David Necas (Yeti) wrote: You have to free it yourself before freeing the list or individual elements. I did it with g_free (filename) but when I use g_print (gslist-data) I get corrupted results. GSList can store some untyped pointers. It has no idea of what they point to (or if they are

Re: GSList and g_filename_from_uri free memory problem

2006-02-23 Thread David Necas (Yeti)
On Thu, Feb 23, 2006 at 09:46:14AM +0100, Colossus wrote: David Necas (Yeti) wrote: You have to free it yourself before freeing the list or ^^ individual elements. ^^^ I did it with g_free (filename) but when I use

Re: GSList and g_filename_from_uri free memory problem

2006-02-23 Thread Stefan Kost
Hi Colossus wrote: Hi, I have this code: 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);

Re: GSList and g_filename_from_uri free memory problem

2006-02-23 Thread David Necas (Yeti)
On Thu, Feb 23, 2006 at 10:19:36AM +0100, Colossus wrote: I don't have to store pointers to freed memory but the filename without file:// and escaped sequences that g_filename_from_uri gives me back ! It does not matter whether you free the memory before or after g_slist_prepend(). The

Re: GSList and g_filename_from_uri free memory problem

2006-02-23 Thread Colossus
David Necas (Yeti) wrote: 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? I don't have to store pointers to freed memory but the filename without file:// and escaped sequences that g_filename_from_uri gives me

Re: GSList and g_filename_from_uri free memory problem

2006-02-23 Thread Colossus
Stefan Kost wrote: just don't fre the filenames now. Free the filenames when you free the list. Ok, but you see the while loop ? if the user drags 10 files from Nautilis window inside Xarchiver ( my app ) window, when I issue g_free later I will only free the last pointer gave me back from

Re: GSList and g_filename_from_uri free memory problem

2006-02-23 Thread Colossus
David Necas (Yeti) wrote: Since the problem seems to be an incorrect assumption of how GSList works and I cannot describe how it actually works more clearly than above, then either by letting someone with better English skills to explain it or by you trying harder to understand me. Ok, I

Re: GSList and g_filename_from_uri free memory problem

2006-02-23 Thread Gaurav Jain
Ok, I understood the matter. Let me explain my problem now: I'm adding drag and drop to my app. To retrieve the content of the selection dropped into the window of my app I use gtk_selection_data_get_uris. The problem is that I get the filename like this: file:///home/gt/GTA%20 and so on.

Re: GSList and g_filename_from_uri free memory problem

2006-02-23 Thread Colossus
Gaurav Jain wrote: All your filenames can be retrieved and freed by looping through the list: Something like: GSList *next_ptr = Files_to_Add; while (next_ptr != NULL) { g_free(next_ptr-data); //this frees the filenames next_ptr = g_slist_next(next_ptr); }

Re: GSList and g_filename_from_uri free memory problem

2006-02-23 Thread Gaurav Jain
On 2/23/06, Colossus [EMAIL PROTECTED] wrote: Gaurav Jain wrote: All your filenames can be retrieved and freed by looping through the list: Something like: GSList *next_ptr = Files_to_Add; while (next_ptr != NULL) { g_free(next_ptr-data); //this frees the filenames

Re: GSList and g_filename_from_uri free memory problem

2006-02-23 Thread Santhosh
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++; } You can do the

Re: GSList and g_filename_from_uri free memory problem

2006-02-23 Thread Colossus
Gaurav Jain wrote: you must pass the list's head node pointer to g_slist_free(), which you will lost if you use Files_to_Add directly (in fact, it will always be null after the while loop) Thank you all, I discovered a memory leak in my code. I was not freeing the data pointer inside the

Re: GSList and g_filename_from_uri free memory problem

2006-02-23 Thread Colossus
Santhosh wrote: I hope this helps... Surely it helps, this way I can free all the pointers in one shot without iterating through the GSList with the while loop. Thank you so much Santosh !! -- Colossus Xarchiver, a Linux GTK+2 only archive manager - http://xarchiver.sourceforge.net