From a8fd49a2340525cfaf1dc4be763a178cd11b16dd Mon Sep 17 00:00:00 2001 From: Cameron Gutman Date: Wed, 6 Jan 2016 12:35:45 -0600 Subject: [PATCH] Fix possible segmentation fault or memory corruption if EVIOCGRAB fails and the cleanup is executed before the device entry is inserted into the list --- app/src/main/jni/evdev_reader/evdev_reader.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/app/src/main/jni/evdev_reader/evdev_reader.c b/app/src/main/jni/evdev_reader/evdev_reader.c index 8c757ce9..00c0ccc8 100644 --- a/app/src/main/jni/evdev_reader/evdev_reader.c +++ b/app/src/main/jni/evdev_reader/evdev_reader.c @@ -132,6 +132,9 @@ cleanup: { struct DeviceEntry *lastEntry; + // Lock the device list + pthread_mutex_lock(&DeviceListLock); + if (DeviceListHead == device) { DeviceListHead = device->next; } @@ -146,6 +149,9 @@ cleanup: lastEntry = lastEntry->next; } } + + // Unlock device list + pthread_mutex_unlock(&DeviceListLock); } // Free the context