Fix overenthusiastic g_free() of Glk startup data
authorP. F. Chimento <philip.chimento@gmail.com>
Sat, 20 Apr 2013 15:42:42 +0000 (17:42 +0200)
committerPhilip Chimento <philip.chimento@gmail.com>
Sat, 31 Aug 2013 23:51:20 +0000 (16:51 -0700)
libchimara/chimara-glk.c

index 74d07724efb78a1e587fba409f820579bff46d63..5d618a991ea78fc04bc5b5eff3d7e6497c99445f 100644 (file)
@@ -1198,19 +1198,21 @@ free_startup_data(struct StartupData *startup)
        while(i < startup->args.argc)
                g_free(startup->args.argv[i++]);
        g_free(startup->args.argv);
        while(i < startup->args.argc)
                g_free(startup->args.argv[i++]);
        g_free(startup->args.argv);
+       g_free(startup);
 }
 
 }
 
-/* glk_enter() is the actual function called in the new thread in which glk_main() runs.  */
+/* glk_enter() is the actual function called in the new thread in which
+glk_main() runs. Takes ownership of @startup and will free it. */
 static gpointer
 glk_enter(struct StartupData *startup)
 {
        extern GPrivate *glk_data_key;
        g_private_set(glk_data_key, startup->glk_data);
 static gpointer
 glk_enter(struct StartupData *startup)
 {
        extern GPrivate *glk_data_key;
        g_private_set(glk_data_key, startup->glk_data);
-       
+
        /* Acquire the Glk thread's references to the input queues */
        g_async_queue_ref(startup->glk_data->char_input_queue);
        g_async_queue_ref(startup->glk_data->line_input_queue);
        /* Acquire the Glk thread's references to the input queues */
        g_async_queue_ref(startup->glk_data->char_input_queue);
        g_async_queue_ref(startup->glk_data->line_input_queue);
-       
+
        /* Run startup function */
        if(startup->glkunix_startup_code) {
                startup->glk_data->in_startup = TRUE;
        /* Run startup function */
        if(startup->glkunix_startup_code) {
                startup->glk_data->in_startup = TRUE;
@@ -1222,18 +1224,17 @@ glk_enter(struct StartupData *startup)
                        return NULL;
                }
        }
                        return NULL;
                }
        }
-       
+
        /* Run main function */
        glk_main_t glk_main = startup->glk_main;
        /* Run main function */
        glk_main_t glk_main = startup->glk_main;
-       
+
        /* COMPAT: avoid usage of slices */
        /* COMPAT: avoid usage of slices */
-       g_free(startup);
-    g_signal_emit_by_name(startup->glk_data->self, "started");
+       g_signal_emit_by_name(startup->glk_data->self, "started");
        glk_main();
        free_startup_data(startup);
        glk_exit(); /* Run shutdown code in glk_exit() even if glk_main() returns normally */
        g_assert_not_reached(); /* because glk_exit() calls g_thread_exit() */
        glk_main();
        free_startup_data(startup);
        glk_exit(); /* Run shutdown code in glk_exit() even if glk_main() returns normally */
        g_assert_not_reached(); /* because glk_exit() calls g_thread_exit() */
-       return NULL; 
+       return NULL;
 }
 
 /**
 }
 
 /**