* 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
This commit is contained in:
Stephan Aßmus 2008-10-24 21:33:46 +00:00
parent 1a1a4f955c
commit 740d899004
2 changed files with 24 additions and 7 deletions

View File

@ -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);

View File

@ -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();