[PATCH evdev] Don't re-open mtdev after PreInit

Peter Hutterer peter.hutterer at who-t.net
Tue Jul 3 16:28:12 PDT 2012


==16557== 388,240 (3,520 direct, 384,720 indirect) bytes in 10 blocks are definitely lost in loss record 1,669 of 1,671
==16557==    at 0x4A06F18: calloc (vg_replace_malloc.c:566)
==16557==    by 0xC3EAD4D: mtdev_new (core.c:345)
==16557==    by 0xC3EAE6B: mtdev_new_open (core.c:383)
==16557==    by 0xC1E0452: EvdevOpenDevice (evdev.c:2365)
==16557==    by 0xC1E068C: EvdevPreInit (evdev.c:2431)
==16557==    by 0x4B8304: xf86NewInputDevice (xf86Xinput.c:846)
==16557==    by 0x4B8857: NewInputDeviceRequest (xf86Xinput.c:989)
==16557==    by 0x4CCB4C: device_added (udev.c:211)
==16557==    by 0x4CCFA6: config_udev_init (udev.c:342)
==16557==    by 0x4CBE81: config_init (config.c:48)
==16557==    by 0x4A8A9A: InitInput (xf86Init.c:918)
==16557==    by 0x4921EE: main (main.c:258)

After PreInit, the fd and mtdev pointer are still valid. We check for the
fd, but unconditionally allocated another mtdev struct for each device.

Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
---
 src/evdev.c |   17 ++++++++++-------
 1 file changed, 10 insertions(+), 7 deletions(-)

diff --git a/src/evdev.c b/src/evdev.c
index c273326..6d264b2 100644
--- a/src/evdev.c
+++ b/src/evdev.c
@@ -2362,13 +2362,16 @@ EvdevOpenDevice(InputInfoPtr pInfo)
     }
 
 #ifdef MULTITOUCH
-    pEvdev->mtdev = mtdev_new_open(pInfo->fd);
-    if (pEvdev->mtdev)
-        pEvdev->cur_slot = pEvdev->mtdev->caps.slot.value;
-    else {
-        xf86Msg(X_ERROR, "%s: Couldn't open mtdev device\n", pInfo->name);
-        EvdevCloseDevice(pInfo);
-        return FALSE;
+    if (!pEvdev->mtdev) { /* after PreInit mtdev is still valid */
+        pEvdev->mtdev = mtdev_new_open(pInfo->fd);
+        xf86IDrvMsg(pInfo, X_ERROR, "mtdev is %p\n", pEvdev->mtdev);
+        if (pEvdev->mtdev)
+            pEvdev->cur_slot = pEvdev->mtdev->caps.slot.value;
+        else {
+            xf86Msg(X_ERROR, "%s: Couldn't open mtdev device\n", pInfo->name);
+            EvdevCloseDevice(pInfo);
+            return FALSE;
+        }
     }
 #endif
 
-- 
1.7.10.4



More information about the xorg-devel mailing list