Fix memory management issues
[platform/upstream/at-spi2-core.git] / registryd / deviceeventcontroller.c
index fabab78..2a0721d 100644 (file)
@@ -6,24 +6,24 @@
  * Copyright 2001, 2002 Ximian, Inc.
  *
  * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Library General Public
+ * modify it under the terms of the GNU Lesser General Public
  * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
+ * version 2.1 of the License, or (at your option) any later version.
  *
  * This library is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Library General Public License for more details.
+ * Lesser General Public License for more details.
  *
- * You should have received a copy of the GNU Library General Public
+ * You should have received a copy of the GNU Lesser General Public
  * License along with this library; if not, write to the
- * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- * Boston, MA 02111-1307, USA.
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
  */
 
 /* deviceeventcontroller.c: implement the DeviceEventController interface */
 
-#include <config.h>
+#include "config.h"
 
 #undef  SPI_XKB_DEBUG
 #undef  SPI_DEBUG
 #include <dbus/dbus.h>
 
 #include "paths.h"
-#include "keymasks.h"
 #include "de-types.h"
 #include "de-marshaller.h"
+#include "keymasks.h"
+
+#ifdef HAVE_X11
 #include "display.h"
 #include "event-source.h"
+#endif
 
 #include "deviceeventcontroller.h"
 #include "reentrant-list.h"
@@ -64,6 +67,7 @@ struct _SpiPoint {
     gint y;
 };
 typedef struct _SpiPoint SpiPoint;
+
 static unsigned int mouse_mask_state = 0;
 static unsigned int key_modifier_mask =
   SPI_KEYMASK_MOD1 | SPI_KEYMASK_MOD2 | SPI_KEYMASK_MOD3 | SPI_KEYMASK_MOD4 |
@@ -634,7 +638,7 @@ handle_keygrab (SpiDEController         *controller,
   grab_mask.mod_mask = key_listener->mask;
   if (g_slist_length (key_listener->keys) == 0) /* special case means AnyKey/AllKeys */
     {
-      grab_mask.key_val = 0L;  /* AnyKey */
+      grab_mask.key_val = 0L; /* AnyKey */
 #ifdef SPI_DEBUG
       fprintf (stderr, "AnyKey grab!");
 #endif
@@ -923,6 +927,7 @@ send_and_allow_reentry (DBusConnection *bus, DBusMessage *message, int timeout,
       {
         const char *dest = dbus_message_get_destination (message);
         GSList *l;
+        dbus_bool_t result;
         gchar *bus_name_dup;
         dbus_message_ref (message);
         dbus_pending_call_set_notify (pending, reset_hung_process, message,
@@ -932,9 +937,9 @@ send_and_allow_reentry (DBusConnection *bus, DBusMessage *message, int timeout,
                                                 "Ping");
         if (!message)
           return NULL;
-        dbus_connection_send_with_reply (bus, message, &pending, -1);
+        result = dbus_connection_send_with_reply (bus, message, &pending, -1);
         dbus_message_unref (message);
-        if (!pending)
+        if (!result || !pending)
           return NULL;
         bus_name_dup = g_strdup (dest);
         dbus_pending_call_set_notify (pending, reset_hung_process_from_ping,
@@ -1361,6 +1366,7 @@ impl_register_keystroke_listener (DBusConnection *bus,
     Accessibility_KeyDefinition *kd = (Accessibility_KeyDefinition *)g_malloc(sizeof(Accessibility_KeyDefinition));
     if (!spi_dbus_message_iter_get_struct(&iter_array, DBUS_TYPE_INT32, &kd->keycode, DBUS_TYPE_INT32, &kd->keysym, DBUS_TYPE_STRING, &keystring, DBUS_TYPE_INVALID))
     {
+      g_free (kd);
       break;
     }
     kd->keystring = g_strdup (keystring);
@@ -1571,6 +1577,7 @@ impl_deregister_keystroke_listener (DBusConnection *bus,
 
     if (!spi_dbus_message_iter_get_struct(&iter_array, DBUS_TYPE_INT32, &kd->keycode, DBUS_TYPE_INT32, &kd->keysym, DBUS_TYPE_STRING, &keystring, DBUS_TYPE_INVALID))
     {
+      g_free(kd);
       break;
     }
     kd->keystring = g_strdup (keystring);
@@ -1758,6 +1765,12 @@ impl_generate_keyboard_event (DBusConnection *bus, DBusMessage *message, void *u
                      fprintf (stderr, "Keystring synthesis failure, string=%s\n",
                               keystring);
              break;
+      case Accessibility_KEY_LOCKMODIFIERS:
+             spi_dec_plat_lock_modifiers (controller, keycode);
+             break;
+      case Accessibility_KEY_UNLOCKMODIFIERS:
+             spi_dec_plat_unlock_modifiers (controller, keycode);
+             break;
     }
   reply = dbus_message_new_method_return (message);
   return reply;
@@ -1846,7 +1859,7 @@ spi_device_event_controller_class_init (SpiDEControllerClass *klass)
   object_class->finalize = spi_device_event_controller_object_finalize;
 
 #ifdef HAVE_X11
-  if (g_getenv ("DISPLAY"))
+  if (g_getenv ("DISPLAY") != NULL && g_getenv ("WAYLAND_DISPLAY") == NULL)
     spi_dec_setup_x11 (klass);
   else
 #endif