peripheral.joystick
peripheral.joystick copied to clipboard
close correctly the uninitialized joysticks
without that closing, the number of open files is growing (can be observed via lsof | grep kodi | grep /dev) and ends to crash kodi after a long time
this is in answer to : https://github.com/batocera-linux/batocera.linux/issues/9086
Fix looks correct. Has the response to the patch been positive in the linked issue?
yes. each patch started with users issues and closed them.
Excellent. Can you apply the following patch to improve code style? If style was perfect I'd merge immediately, but that can't really be expected for a many-year-old codebase that never adopted clang-format.
--- a/src/api/udev/JoystickInterfaceUdev.cpp
+++ b/src/api/udev/JoystickInterfaceUdev.cpp
@@ -92,13 +92,9 @@ bool CJoystickInterfaceUdev::ScanForJoysticks(JoystickVector& joysticks)
if (devnode != nullptr)
{
- CJoystickUdev *j = new CJoystickUdev(dev, devnode);
- if(j->isInitialized()) {
- JoystickPtr joystick = JoystickPtr(j);
- joysticks.push_back(joystick);
- } else {
- delete j;
- }
+ std::shared_ptr<CJoystickUdev>joystick = std::make_shared<CJoystickUdev>(dev, devnode);
+ if (joystick->IsInitialized())
+ joysticks.emplace_back(std::move(joystick));
}
udev_device_unref(dev);
diff --git a/src/api/udev/JoystickUdev.h b/src/api/udev/JoystickUdev.h
index 949d2f2..98f0d3a 100644
--- a/src/api/udev/JoystickUdev.h
+++ b/src/api/udev/JoystickUdev.h
@@ -58,7 +58,9 @@ namespace JOYSTICK
virtual bool Initialize(void) override;
virtual void Deinitialize(void) override;
virtual void ProcessEvents(void) override;
- bool isInitialized() { return m_bInitialized; }
+
+ // udev API
+ bool IsInitialized() const { return m_bInitialized; }
protected:
// implementation of CJoystick
Merged with proposed change in c6c20b0474a835fad83d85c83ad3e6b8df8a98d6. Thanks!