g_main_context_unref



Hello,

I would like to unref the default main context after use for proper cleanup. However, this leaves a dangerous invalid pointer in default_main_context. Should this be fixed? I am not quite sure about the locking/atomic issues though.

Carsten

--- gmain-orig.c        2004-11-08 19:49:35.000000000 +0100
+++ gmain.c     2005-01-27 10:09:32.000000000 +0100
@@ -637,8 +637,17 @@
   g_return_if_fail (context != NULL);
   g_return_if_fail (g_atomic_int_get (&context->ref_count) > 0);

+  G_LOCK (main_loop);
   if (!g_atomic_int_dec_and_test (&context->ref_count))
-    return;
+    {
+      G_UNLOCK (main_loop);
+      return;
+    }
+  if (context == default_main_context)
+    {
+      default_main_context = NULL;
+    }
+  G_UNLOCK (main_loop);

   G_LOCK (main_context_list);
   main_context_list = g_slist_remove (main_context_list, context)



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