2005-11-17 Michael Meeks <michael.meeks@novell.com>
[platform/core/uifw/at-spi2-atk.git] / atk-bridge / bridge.c
index 45155e0..096a5ad 100644 (file)
@@ -49,6 +49,7 @@ static SpiApplication *this_app = NULL;
 static gboolean registry_died = FALSE;
 static gboolean atk_listeners_registered = FALSE;
 static gint toplevels = 0;
+static gboolean exiting = FALSE;
 
 static guint atk_signal_text_changed;
 static guint atk_signal_children_changed;
@@ -160,8 +161,10 @@ atk_bridge_init (gint *argc, gchar **argv[])
 
   if (g_getenv ("ATK_BRIDGE_REDIRECT_LOG"))
   {
-      fname = g_strconcat ("/tmp/", g_get_prgname (), ".at-spi-log");
-      freopen (fname, "w", stderr);
+      fname = g_strconcat ("/tmp/", g_get_prgname (), ".at-spi-log", NULL);
+      /* make sure we're not being redirected - security issue */
+      if (!g_file_test (fname, G_FILE_TEST_IS_SYMLINK))
+         freopen (fname, "w", stderr);
       g_free (fname);
   }
 
@@ -316,8 +319,12 @@ spi_atk_bridge_get_registry (void)
   if (registry_died || (registry == CORBA_OBJECT_NIL)) {
          CORBA_exception_init (&ev);
          if (registry_died) 
-           DBG (1, g_warning ("registry died! restarting..."));
-         
+            {
+              if (exiting)
+                return CORBA_OBJECT_NIL;
+              else
+               DBG (1, g_warning ("registry died! restarting..."));
+            }
          bonobo_activation_set_activation_env_value ("AT_SPI_DISPLAY", spi_display_name ());
 
          registry = bonobo_activation_activate_from_id (
@@ -492,6 +499,7 @@ spi_atk_bridge_exit_func (void)
       _exit (0);
     }
 
+  exiting = TRUE;
   /*
    * Check whether we still have windows which have not been deleted.
    */
@@ -508,7 +516,8 @@ spi_atk_bridge_exit_func (void)
       g_assert (bonobo_activate ());
     }
   
-  deregister_application (app);
+  if (!registry_died)
+    deregister_application (app);
 
   DBG (1, g_message ("bridge exit func complete.\n"));
 
@@ -596,6 +605,7 @@ spi_atk_emit_eventv (const GObject         *gobject,
   Accessibility_Event e;
   SpiAccessible      *source;
   AtkObject          *aobject;
+  Accessibility_Registry registry;
 #ifdef SPI_BRIDGE_DEBUG
   CORBA_string s;
 #endif
@@ -636,7 +646,12 @@ spi_atk_emit_eventv (const GObject         *gobject,
       CORBA_free (s);
 #endif
       CORBA_exception_init (&ev);
-      Accessibility_Registry_notifyEvent (spi_atk_bridge_get_registry (), 
+      registry = spi_atk_bridge_get_registry ();
+      if (registry_died) {
+        g_free (e.type);
+        return;
+      }  
+      Accessibility_Registry_notifyEvent (registry, 
                                          &e, &ev);
 #ifdef SPI_BRIDGE_DEBUG
       if (ev._major != CORBA_NO_EXCEPTION)
@@ -646,7 +661,7 @@ spi_atk_emit_eventv (const GObject         *gobject,
                   CORBA_exception_id(&ev));
 #endif       
       if (BONOBO_EX (&ev)) registry_died = TRUE;
-      Accessibility_Accessible_unref (e.source, &ev);
+      bonobo_object_unref (BONOBO_OBJECT (source));
       
       CORBA_exception_free (&ev);
       
@@ -917,7 +932,6 @@ spi_atk_bridge_signal_listener (GSignalInvocationHint *signal_hint,
   CORBA_Object c_obj;
   char *sp = NULL;
   AtkObject *ao;
-  AtkText *text;
   gint detail1 = 0, detail2 = 0;
   SpiAccessible *s_ao = NULL;
 #ifdef SPI_BRIDGE_DEBUG
@@ -1007,8 +1021,6 @@ spi_atk_bridge_signal_listener (GSignalInvocationHint *signal_hint,
         }
       else if (signal_query.signal_id == atk_signal_text_selection_changed)
         {
-          text = ATK_TEXT (gobject);
           /* Return NULL as the selected string */
          spi_init_any_nil (&any);
         }
@@ -1027,6 +1039,8 @@ spi_atk_bridge_signal_listener (GSignalInvocationHint *signal_hint,
 
   if (sp)
     g_free (sp);
+  if (any._release)
+    CORBA_free (any._value);
 
   return TRUE;
 }
@@ -1090,6 +1104,8 @@ spi_atk_tidy_windows (void)
       if (atk_state_set_contains_state (stateset, ATK_STATE_ACTIVE))
         {
           spi_atk_emit_eventv (G_OBJECT (child), 0, 0, &any, "window:deactivate");
+          if (registry_died)
+            return;
         }
       g_object_unref (stateset);