[PATCH evdev 1/2] Release leaked XKB options on input device disconnect.

Rami Ylimäki rami.ylimaki at vincit.fi
Fri Mar 4 03:18:53 PST 2011


Currently the XKB options duplicated in EvdevAddKeyClass are never
released. For example, connecting and disconnecting a bluetooth
keyboard repeatedly causes a steadily growing memory leak.

Signed-off-by: Rami Ylimäki <rami.ylimaki at vincit.fi>
Reviewed-by: Erkki Seppälä <erkki.seppala at vincit.fi>
---
 src/evdev.c |   19 ++++++++++++++++++-
 1 files changed, 18 insertions(+), 1 deletions(-)

diff --git a/src/evdev.c b/src/evdev.c
index bb30655..a77be9e 100644
--- a/src/evdev.c
+++ b/src/evdev.c
@@ -1826,6 +1826,23 @@ EvdevOpenDevice(InputInfoPtr pInfo)
     return Success;
 }
 
+static void
+EvdevUnInit(InputDriverPtr drv, InputInfoPtr pInfo, int flags)
+{
+    EvdevPtr pEvdev = pInfo ? pInfo->private : NULL;
+    if (pEvdev)
+    {
+        /* Release strings allocated in EvdevAddKeyClass. */
+        free(pEvdev->rmlvo.rules);
+        free(pEvdev->rmlvo.model);
+        free(pEvdev->rmlvo.layout);
+        free(pEvdev->rmlvo.variant);
+        free(pEvdev->rmlvo.options);
+        memset(&pEvdev->rmlvo, 0, sizeof(pEvdev->rmlvo));
+    }
+    xf86DeleteInput(pInfo, flags);
+}
+
 static int
 EvdevPreInit(InputDriverPtr drv, InputInfoPtr pInfo, int flags)
 {
@@ -1897,7 +1914,7 @@ _X_EXPORT InputDriverRec EVDEV = {
     "evdev",
     NULL,
     EvdevPreInit,
-    NULL,
+    EvdevUnInit,
     NULL,
     evdevDefaults
 };
-- 
1.6.3.3



More information about the xorg-devel mailing list