xbmc / peripheral.joystick

Kodi joystick support (drivers and button maps)
GNU General Public License v2.0
24 stars 46 forks source link

close correctly the uninitialized joysticks #276

Closed nadenislamarre closed 4 months ago

nadenislamarre commented 1 year ago

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

nadenislamarre commented 1 year ago

this is in answer to : https://github.com/batocera-linux/batocera.linux/issues/9086

garbear commented 1 year ago

Fix looks correct. Has the response to the patch been positive in the linked issue?

nadenislamarre commented 1 year ago

yes. each patch started with users issues and closed them.

garbear commented 1 year ago

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
garbear commented 4 months ago

Merged with proposed change in c6c20b0474a835fad83d85c83ad3e6b8df8a98d6. Thanks!