[prevent][42562] Fix for resource leakage
[platform/upstream/at-spi2-core.git] / registryd / deviceeventcontroller.c
index 6d04a27..a7d3769 100644 (file)
 #include "keymasks.h"
 #include "de-types.h"
 #include "de-marshaller.h"
+#ifdef HAVE_X11
 #include "display.h"
 #include "event-source.h"
+#endif
 
 #include "deviceeventcontroller.h"
 #include "reentrant-list.h"
@@ -65,9 +67,14 @@ struct _SpiPoint {
 };
 typedef struct _SpiPoint SpiPoint;
 static unsigned int mouse_mask_state = 0;
+#ifdef HAVE_X11
 static unsigned int key_modifier_mask =
   Mod1Mask | Mod2Mask | Mod3Mask | Mod4Mask | Mod5Mask | ShiftMask | LockMask | ControlMask | SPI_KEYMASK_NUMLOCK;
 static unsigned int _numlock_physical_mask = Mod2Mask; /* a guess, will be reset */
+#else
+static unsigned int key_modifier_mask = 255;
+static unsigned int _numlock_physical_mask = (1<<4);
+#endif
 
 static gboolean have_mouse_listener = FALSE;
 static gboolean have_mouse_event_listener = FALSE;
@@ -380,7 +387,9 @@ spi_dec_poll_mouse_idle (gpointer data)
     return TRUE;
   else
     {
-      g_timeout_add (20, spi_dec_poll_mouse_moving, data);         
+      guint id;
+      id = g_timeout_add (20, spi_dec_poll_mouse_moving, data);
+      g_source_set_name_by_id (id, "[at-spi2-core] spi_dec_poll_mouse_moving");
       return FALSE;        
     }
 }
@@ -394,7 +403,9 @@ spi_dec_poll_mouse_moving (gpointer data)
     return TRUE;
   else
     {
-      g_timeout_add (100, spi_dec_poll_mouse_idle, data);          
+      guint id;
+      id = g_timeout_add (100, spi_dec_poll_mouse_idle, data);
+      g_source_set_name_by_id (id, "[at-spi2-core] check_release");
       return FALSE;
     }
 }
@@ -628,7 +639,12 @@ handle_keygrab (SpiDEController         *controller,
   grab_mask.mod_mask = key_listener->mask;
   if (g_slist_length (key_listener->keys) == 0) /* special case means AnyKey/AllKeys */
     {
+#ifdef HAVE_X11
       grab_mask.key_val = AnyKey;
+#else
+      grab_mask.key_val = 0L;
+#endif
+
 #ifdef SPI_DEBUG
       fprintf (stderr, "AnyKey grab!");
 #endif
@@ -824,8 +840,11 @@ spi_controller_register_device_listener (SpiDEController      *controller,
       if (!have_mouse_listener)
         {
           have_mouse_listener = TRUE;
-          if (!have_mouse_event_listener)
-            g_timeout_add (100, spi_dec_poll_mouse_idle, controller);
+          if (!have_mouse_event_listener) {
+            guint id;
+            id = g_timeout_add (100, spi_dec_poll_mouse_idle, controller);
+            g_source_set_name_by_id (id, "[at-spi2-core] spi_dec_poll_mouse_idle");
+          }
         }
       spi_dbus_add_disconnect_match (controller->bus, listener->bus_name);
       notify_mouse_listener (controller, listener, TRUE);
@@ -1352,6 +1371,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);
@@ -1562,6 +1582,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);
@@ -1742,7 +1763,11 @@ impl_generate_keyboard_event (DBusConnection *bus, DBusMessage *message, void *u
               * in our arg list; it can contain either
               * a keycode or a keysym.
               */
+#ifdef HAVE_X11
              spi_dec_synth_keysym (controller, (KeySym) keycode);
+#else
+             spi_dec_synth_keysym (controller, (long) keycode);
+#endif
              break;
       case Accessibility_KEY_STRING:
              if (!spi_dec_plat_synth_keystring (controller, synth_type, keycode, keystring))
@@ -1988,8 +2013,10 @@ handle_dec_method (DBusConnection *bus, DBusMessage *message, void *user_data)
   dbus_message_ref (message);
   g_queue_push_tail (saved_controller->message_queue, message);
   g_queue_push_tail (saved_controller->message_queue, user_data);
-  if (!saved_controller->message_queue_idle)
+  if (!saved_controller->message_queue_idle) {
     saved_controller->message_queue_idle = g_idle_add (message_queue_dispatch, NULL);
+    g_source_set_name_by_id (saved_controller->message_queue_idle, "[at-spi2-core] message_queue_dispatch");
+  }
   return DBUS_HANDLER_RESULT_HANDLED;
 }
 
@@ -2020,8 +2047,11 @@ spi_device_event_controller_start_poll_mouse (SpiRegistry *registry)
   if (!have_mouse_event_listener)
     {
       have_mouse_event_listener = TRUE;
-      if (!have_mouse_listener)
-      g_timeout_add (100, spi_dec_poll_mouse_idle, registry->dec);
+      if (!have_mouse_listener) {
+        guint id;
+        id = g_timeout_add (100, spi_dec_poll_mouse_idle, registry->dec);
+        g_source_set_name_by_id (id, "[at-spi2-core] spi_dec_poll_mouse_idle");
+      }
     }
 }