Re: [gnome-love] New file selector?



Thanks for that.
I now have another memory-related question.

I'm just wondering how to safely remove things out of a GSList without
having a memory leak.  I didn't find the documentation explicit.

So I have a block of code that looks like this:
GSList *gslist;

fileRequ = gtk_file_chooser_dialog_new(big list of options);
gtk_file_chooser_set_select_multiple ((GtkFileChooser *)fileRequ, TRUE);

g_signal_connect(GTK_FILE_CHOOSER (fileRequ), "destroy",
(GtkSignalFunc)fileSelDialogDestroyed, &fileRequ);

gtk_dialog_run(GTK_DIALOG(fileRequ);

/* here's where my question actually begins */
gslist = gtk_file_chooser_get_filenames(GTK_FILE_CHOOSER(fileRequ));
while(gslist)
{
   printf("%s\n",(char *)gslist->data);
   g_free(gslist->data);
   list = g_slist_remove(gslist, gslist->data);
}
g_slist_free(gslist);
gtk_widget_destroy(fileRequ);

What I want to do is remove an element off of the front of the GSList,
use it, and then free it.
In the code above, does the g_slist_remove free the list element, or
do I need to do a g_free on each individual element?  According to the
gtk_file_chooser_get_filenames documentation, it says that the g_free
is required for each element.  In that case, there's the g_free
followed by a g_slist_remove... does it care that it's pointing to an
already freed element?

Could somebody tell me the correct way to free each element?

Also, in the documentation, it says that gtk_clist_* is deprecated. 
Does anyone know the GTK 2.4 equivalent of it?

Thanks,
Jeramy

On Wed, 17 Nov 2004 15:57:09 -0600, James M. Cape <jcape ignore-your tv> wrote:
On Wed, 2004-11-17 at 08:38 +0000, nelson wrote:

#if GTK_CHECK_VERSION(2,4,0)
              
gtk_entry_set_text(GTK_ENTRY(app->fileentry),gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(file_selector)));
#else

This, unfortunately, is a memory leak, as
gtk_file_chooser_get_filename() returns a newly allocated string, which
you must free. Try this instead:

#if GTK_CHECK_VERSION(2,4,0)
        gchar *filename =
gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(file_selector));
        gtk_entry_set_text (GTK_ENTRY (app->fileentry),filename);
        g_free (filename);
#else

--
Peace,

    Jim Cape
    http://esco.mine.nu
    http://ignore-your.tv

    "If even one reporter had stood up during a pre-Iraq Bush press
     conference last year and shouted, `Bullshit!' it might have made a
     difference."
        -- Matt Taibbi, New York Press


_______________________________________________
gnome-love mailing list
gnome-love gnome org
http://mail.gnome.org/mailman/listinfo/gnome-love






-- 
Mozilla Firefox:  Use a better Web browser:  http://www.mozilla.org/

Please avoid sending me Word or PowerPoint attachments.
See http://www.fsf.org/philosophy/no-word-attachments.html



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