proper way to clean up



I have a structure that contains all my widgets:

typedef struct {
    GtkWidget *window;
    GtkWidget *vbox;
    GtkWidget *hbox;
    GtkWidget *label;
    GtkWidget *button;
} Window;

And in main() I do:

Window *win = g_malloc(sizeof(Window *));
gtk_init(&argc, &argv);
win->window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_signal_connect(GTK_OBJECT(win->window), "destroy",
        GTK_SIGNAL_FUNC(main_destroy_cb), win);
...

now the callback main_destroy_cb:

void main_destroy_cb(GtkWidget *widget, Window *win)
{
    g_free(win);
    gtk_main_quit();
}

Is this the proper way to malloc and free memory on exit for the Window
structure?
Also, if the Window structure is not free'd, it would end up in a memory
leak, correct?

Thanks,
Aaron

--
Visit my web site at http://iconmedia.com/cgi-bin/index.pl

Current uptime:
 10:48am  up 12:45,  1 user,  load average: 0.29, 0.18, 0.07





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