From ae4847f3dc67b8bdddf6e3e8dbec0348995efaef Mon Sep 17 00:00:00 2001 From: "P. F. Chimento" Date: Sat, 13 Nov 2010 01:20:21 +0100 Subject: [PATCH] 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. --- libchimara/chimara-glk.c | 2 ++ libchimara/style.c | 1 + tests/.gitignore | 1 + tests/Makefile.am | 6 +++++- tests/test-close.c | 39 +++++++++++++++++++++++++++++++++++++++ 5 files changed, 48 insertions(+), 1 deletion(-) create mode 100644 tests/test-close.c 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; +} -- 2.30.2