[xorg-x11-drv-evdev] Don't leak mtdev data

Peter Hutterer whot at fedoraproject.org
Tue Jul 3 22:17:06 UTC 2012


commit cdc48c2c0e2cc51f78b670b778471771d0c573b1
Author: Peter Hutterer <peter.hutterer at who-t.net>
Date:   Wed Jul 4 08:21:34 2012 +1000

    Don't leak mtdev data

 ...lease-mtdev-data-whenever-we-close-the-fd.patch |  112 ++++++++++++++++++++
 xorg-x11-drv-evdev.spec                            |    7 +-
 2 files changed, 118 insertions(+), 1 deletions(-)
---
diff --git a/0001-Release-mtdev-data-whenever-we-close-the-fd.patch b/0001-Release-mtdev-data-whenever-we-close-the-fd.patch
new file mode 100644
index 0000000..300b16b
--- /dev/null
+++ b/0001-Release-mtdev-data-whenever-we-close-the-fd.patch
@@ -0,0 +1,112 @@
+From ac5173163d7d1e18d47630a397ece0f26b2568c8 Mon Sep 17 00:00:00 2001
+From: Peter Hutterer <peter.hutterer at who-t.net>
+Date: Mon, 28 May 2012 09:08:43 +1000
+Subject: [PATCH evdev] Release mtdev data whenever we close the fd
+
+Add a new EvdevCloseDevice() function to unify this.
+We used to leak data
+- PreInit allocates mtdev, but nothing except one error path released it.
+- each DEVICE_ON re-allocates mtdev but it is never released
+
+Reported-by: Zdenek Kabelac <zdenek.kabelac at gmail.com>
+Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
+Reviewed-by: Chase Douglas <chase.douglas at canonical.com>
+---
+ src/evdev.c |   38 +++++++++++++++++++++++++-------------
+ 1 file changed, 25 insertions(+), 13 deletions(-)
+
+diff --git a/src/evdev.c b/src/evdev.c
+index 055bc3f..fb44c37 100644
+--- a/src/evdev.c
++++ b/src/evdev.c
+@@ -119,6 +119,7 @@ static int EvdevSwitchMode(ClientPtr client, DeviceIntPtr device, int mode);
+ static BOOL EvdevGrabDevice(InputInfoPtr pInfo, int grab, int ungrab);
+ static void EvdevSetCalibration(InputInfoPtr pInfo, int num_calibration, int calibration[4]);
+ static int EvdevOpenDevice(InputInfoPtr pInfo);
++static void EvdevCloseDevice(InputInfoPtr pInfo);
+ 
+ static void EvdevInitAxesLabels(EvdevPtr pEvdev, int mode, int natoms, Atom *atoms);
+ static void EvdevInitButtonLabels(EvdevPtr pEvdev, int natoms, Atom *atoms);
+@@ -1108,8 +1109,7 @@ EvdevReadInput(InputInfoPtr pInfo)
+                 EvdevMBEmuFinalize(pInfo);
+                 Evdev3BEmuFinalize(pInfo);
+                 xf86RemoveEnabledDevice(pInfo);
+-                close(pInfo->fd);
+-                pInfo->fd = -1;
++                EvdevCloseDevice(pInfo);
+             } else if (errno != EAGAIN)
+             {
+                 /* We use X_NONE here because it doesn't alloc */
+@@ -1866,8 +1866,7 @@ EvdevProc(DeviceIntPtr device, int what)
+         {
+             EvdevGrabDevice(pInfo, 0, 1);
+             xf86RemoveEnabledDevice(pInfo);
+-            close(pInfo->fd);
+-            pInfo->fd = -1;
++            EvdevCloseDevice(pInfo);
+         }
+         pEvdev->min_maj = 0;
+         pEvdev->flags &= ~EVDEV_INITIALIZED;
+@@ -1876,10 +1875,7 @@ EvdevProc(DeviceIntPtr device, int what)
+ 
+     case DEVICE_CLOSE:
+ 	xf86IDrvMsg(pInfo, X_INFO, "Close\n");
+-        if (pInfo->fd != -1) {
+-            close(pInfo->fd);
+-            pInfo->fd = -1;
+-        }
++        EvdevCloseDevice(pInfo);
+         EvdevFreeMasks(pEvdev);
+         EvdevRemoveDevice(pInfo);
+         pEvdev->min_maj = 0;
+@@ -2368,17 +2364,34 @@ EvdevOpenDevice(InputInfoPtr pInfo)
+     if (EvdevIsDuplicate(pInfo))
+     {
+         xf86IDrvMsg(pInfo, X_WARNING, "device file is duplicate. Ignoring.\n");
++        EvdevCloseDevice(pInfo);
++        return BadMatch;
++    }
++
++    return Success;
++}
++
++static void
++EvdevCloseDevice(InputInfoPtr pInfo)
++{
++    EvdevPtr pEvdev = pInfo->private;
++    if (pInfo->fd >= 0)
++    {
+         close(pInfo->fd);
++        pInfo->fd = -1;
++    }
++
+ #ifdef MULTITOUCH
++    if (pEvdev->mtdev)
++    {
+         mtdev_close_delete(pEvdev->mtdev);
+         pEvdev->mtdev = NULL;
+-#endif
+-        return BadMatch;
+     }
++#endif
+ 
+-    return Success;
+ }
+ 
++
+ static void
+ EvdevUnInit(InputDriverPtr drv, InputInfoPtr pInfo, int flags)
+ {
+@@ -2459,8 +2472,7 @@ EvdevPreInit(InputDriverPtr drv, InputInfoPtr pInfo, int flags)
+     return Success;
+ 
+ error:
+-    if (pInfo->fd >= 0)
+-        close(pInfo->fd);
++    EvdevCloseDevice(pInfo);
+     return rc;
+ }
+ 
+-- 
+1.7.10.4
+
diff --git a/xorg-x11-drv-evdev.spec b/xorg-x11-drv-evdev.spec
index 5b3460c..3de9376 100644
--- a/xorg-x11-drv-evdev.spec
+++ b/xorg-x11-drv-evdev.spec
@@ -8,7 +8,7 @@
 Summary:    Xorg X11 evdev input driver
 Name:       xorg-x11-drv-evdev
 Version:    2.7.0
-Release:    3%{?gitdate:.%{gitdate}git%{gitversion}}%{dist}
+Release:    4%{?gitdate:.%{gitdate}git%{gitversion}}%{dist}
 URL:        http://www.x.org
 License:    MIT
 Group:      User Interface/X Hardware Support
@@ -24,6 +24,8 @@ Source0:    ftp://ftp.x.org/pub/individual/driver/%{tarball}-%{version}.tar.bz2
 Patch01: 0001-Fix-inverted-horizontal-scroll-46205.patch
 # Bug 805902 - Scrollwheels on tablets are broken
 Patch02: 0001-Allow-relative-scroll-valuators-on-absolute-devices.patch
+# Don't leak mtdev data
+Patch03: 0001-Release-mtdev-data-whenever-we-close-the-fd.patch
 
 ExcludeArch: s390 s390x %{?rhel:ppc ppc64}
 
@@ -85,6 +87,9 @@ X.Org X11 evdev input driver development files.
 
 
 %changelog
+* Wed Jul 04 2012 Peter Hutterer <peter.hutterer at redhat.com> 2.7.0-4
+- Don't leak mtdev data
+
 * Thu Apr 05 2012 Adam Jackson <ajax at redhat.com> - 2.7.0-3
 - RHEL arch exclude updates
 


More information about the scm-commits mailing list