Fix possible segmentation fault or memory corruption if EVIOCGRAB fails and the cleanup is executed before the device entry is inserted into the list

This commit is contained in:
Cameron Gutman 2016-01-06 12:35:45 -06:00
parent 006ad72eb2
commit a8fd49a234

View File

@ -132,6 +132,9 @@ cleanup:
{ {
struct DeviceEntry *lastEntry; struct DeviceEntry *lastEntry;
// Lock the device list
pthread_mutex_lock(&DeviceListLock);
if (DeviceListHead == device) { if (DeviceListHead == device) {
DeviceListHead = device->next; DeviceListHead = device->next;
} }
@ -146,6 +149,9 @@ cleanup:
lastEntry = lastEntry->next; lastEntry = lastEntry->next;
} }
} }
// Unlock device list
pthread_mutex_unlock(&DeviceListLock);
} }
// Free the context // Free the context