[PATCH weston 12/20] compositor-drm: fix leak in evdev_udev_handler()

Pekka Paalanen ppaalanen at gmail.com
Fri Aug 3 04:39:08 PDT 2012


If the sysname of the udev device did not start with "event", the
function returned without unreferencing udev_device.

The function is refactored to have a common exit path that unrefs
udev_device. The return value semantics are not changed.

Signed-off-by: Pekka Paalanen <ppaalanen at gmail.com>
---
 src/compositor-drm.c |   36 +++++++++++++++++++-----------------
 1 files changed, 19 insertions(+), 17 deletions(-)

diff --git a/src/compositor-drm.c b/src/compositor-drm.c
index efbc6eb..7888ce1 100644
--- a/src/compositor-drm.c
+++ b/src/compositor-drm.c
@@ -1868,34 +1868,36 @@ evdev_add_devices(struct udev *udev, struct weston_seat *seat_base)
 static int
 evdev_udev_handler(int fd, uint32_t mask, void *data)
 {
-	struct drm_seat *master = data;
+	struct drm_seat *seat = data;
 	struct udev_device *udev_device;
 	struct evdev_input_device *device, *next;
 	const char *action;
 	const char *devnode;
 
-	udev_device = udev_monitor_receive_device(master->udev_monitor);
+	udev_device = udev_monitor_receive_device(seat->udev_monitor);
 	if (!udev_device)
 		return 1;
 
 	action = udev_device_get_action(udev_device);
-	if (action) {
-		if (strncmp("event", udev_device_get_sysname(udev_device), 5) != 0)
-			return 0;
+	if (!action)
+		goto out;
 
-		if (!strcmp(action, "add")) {
-			device_added(udev_device, master);
-		}
-		else if (!strcmp(action, "remove")) {
-			devnode = udev_device_get_devnode(udev_device);
-			wl_list_for_each_safe(device, next,
-					      &master->devices_list, link)
-				if (!strcmp(device->devnode, devnode)) {
-					evdev_input_device_destroy(device);
-					break;
-				}
-		}
+	if (strncmp("event", udev_device_get_sysname(udev_device), 5) != 0)
+		goto out;
+
+	if (!strcmp(action, "add")) {
+		device_added(udev_device, seat);
 	}
+	else if (!strcmp(action, "remove")) {
+		devnode = udev_device_get_devnode(udev_device);
+		wl_list_for_each_safe(device, next, &seat->devices_list, link)
+			if (!strcmp(device->devnode, devnode)) {
+				evdev_input_device_destroy(device);
+				break;
+			}
+	}
+
+out:
 	udev_device_unref(udev_device);
 
 	return 0;
-- 
1.7.8.6



More information about the wayland-devel mailing list