From: P. F. Chimento Date: Sat, 13 Nov 2010 00:20:21 +0000 (+0100) Subject: Fixed memory management in styles X-Git-Tag: v0.9~174 X-Git-Url: https://git.stderr.nl/gitweb?a=commitdiff_plain;h=ae4847f3dc67b8bdddf6e3e8dbec0348995efaef;p=projects%2Fchimara%2Fchimara.git Fixed memory management in styles Added a free for the StyleSets that were leaked, and fixed a double unref of text tags that was causing lots of warnings when closing the widget. Also added a test case. --- diff --git a/libchimara/chimara-glk.c b/libchimara/chimara-glk.c index bbdb614..5cdf63e 100644 --- a/libchimara/chimara-glk.c +++ b/libchimara/chimara-glk.c @@ -305,6 +305,8 @@ chimara_glk_finalize(GObject *object) g_free(priv->program_name); g_free(priv->program_info); g_free(priv->story_name); + g_free(priv->styles); + g_free(priv->glk_styles); /* Chain up to parent */ G_OBJECT_CLASS(chimara_glk_parent_class)->finalize(object); diff --git a/libchimara/style.c b/libchimara/style.c index 9fc6b1e..4785b90 100644 --- a/libchimara/style.c +++ b/libchimara/style.c @@ -376,6 +376,7 @@ style_init(ChimaraGlk *glk) for(i=0; i +#include + +int +main(int argc, char *argv[]) +{ + GtkWidget *window, *glk; + + /* Initialize threads and GTK */ + if(!g_thread_supported()) + g_thread_init(NULL); + gdk_threads_init(); + gtk_init(&argc, &argv); + + /* Construct the window and its contents. We quit the GTK main loop + * when the window's close button is clicked. */ + window = gtk_window_new(GTK_WINDOW_TOPLEVEL); + g_signal_connect(window, "delete-event", G_CALLBACK(gtk_main_quit), NULL); + glk = chimara_glk_new(); + gtk_container_add(GTK_CONTAINER(window), glk); + gtk_widget_show_all(window); + + /* Add a reference to the ChimaraGlk widget, because we want to keep it + around after gtk_main() exits */ + g_object_ref(glk); + + /* Start the GTK main loop */ + gdk_threads_enter(); + gtk_main(); + gdk_threads_leave(); + + /* After the GTK main loop exits, signal the Glk program to shut down if + * it is still running, and wait for it to exit. */ + chimara_glk_stop(CHIMARA_GLK(glk)); + chimara_glk_wait(CHIMARA_GLK(glk)); + g_object_unref(glk); + + return 0; +}