From 740d899004c043491beee363479dd9b47606d4f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20A=C3=9Fmus?= Date: Fri, 24 Oct 2008 21:33:46 +0000 Subject: [PATCH] * InputDeviceListItem::fDevice was not maintaining it's own memory for the device path, but instead pointing to memory owned by some device addon instance. * Added TODO in the AddOnManager init code about a possible race condition which I have not varified yet. * Check the return code of BList::RemoveItem() before deleting the item... pure defensive programming. * For the time being, print a warning into the syslog when a device name is registered twice. * When failing to Unflatten() an event, don't continue in the code after deleting it. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@28319 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/servers/input/InputServer.cpp | 28 ++++++++++++++++++++++------ src/servers/input/InputServer.h | 3 ++- 2 files changed, 24 insertions(+), 7 deletions(-) diff --git a/src/servers/input/InputServer.cpp b/src/servers/input/InputServer.cpp index 1d92db8987..4ec6faddf7 100644 --- a/src/servers/input/InputServer.cpp +++ b/src/servers/input/InputServer.cpp @@ -64,13 +64,25 @@ KeymapMethod InputServer::gKeymapMethod; extern "C" _EXPORT BView* instantiate_deskbar_item(); +// #pragma mark - InputDeviceListItem + + InputDeviceListItem::InputDeviceListItem(BInputServerDevice& serverDevice, - input_device_ref& device) + const input_device_ref& device) : fServerDevice(&serverDevice), - fDevice(device), + fDevice(), fRunning(false) { + fDevice.name = strdup(device.name); + fDevice.type = device.type; + fDevice.cookie = device.cookie; +} + + +InputDeviceListItem::~InputDeviceListItem() +{ + free(fDevice.name); } @@ -217,6 +229,8 @@ InputServer::InputServer() fAddOnManager = new(std::nothrow) ::AddOnManager(SafeMode()); if (fAddOnManager != NULL) { fAddOnManager->Run(); + // TODO: The BLooper thread may already start running here, + // is this a problem? fAddOnManager->LoadState(); } @@ -1124,8 +1138,8 @@ InputServer::UnregisterDevices(BInputServerDevice& serverDevice, if (item->ServerDevice() == &serverDevice && item->HasName(device->name)) { item->Stop(); - fInputDeviceList.RemoveItem(j); - delete item; + if (fInputDeviceList.RemoveItem(j)) + delete item; break; } } @@ -1137,8 +1151,8 @@ InputServer::UnregisterDevices(BInputServerDevice& serverDevice, if (item->ServerDevice() == &serverDevice) { item->Stop(); - fInputDeviceList.RemoveItem(i); - delete item; + if (fInputDeviceList.RemoveItem(i)) + delete item; } } } @@ -1170,6 +1184,7 @@ InputServer::RegisterDevices(BInputServerDevice& serverDevice, InputDeviceListItem* item = (InputDeviceListItem*)fInputDeviceList.ItemAt(j); if (item->HasName(device->name)) { +debug_printf("InputServer::RegisterDevices() device_ref already exists: %s\n", device->name); PRINT(("RegisterDevices found %s\n", device->name)); found = true; break; @@ -1396,6 +1411,7 @@ InputServer::_EventLoop() if ((err = event->Unflatten(buffer)) < 0) { PRINTERR(("[InputServer] Unflatten() error: (0x%lx) %s\n", err, strerror(err))); delete event; + continue; } events.AddItem(event); diff --git a/src/servers/input/InputServer.h b/src/servers/input/InputServer.h index ca02f61aab..079d75bb60 100644 --- a/src/servers/input/InputServer.h +++ b/src/servers/input/InputServer.h @@ -44,7 +44,8 @@ class BottomlineWindow; class InputDeviceListItem { public: InputDeviceListItem(BInputServerDevice& serverDevice, - input_device_ref& device); + const input_device_ref& device); + ~InputDeviceListItem(); void Start(); void Stop();