From: Pierre Schweitzer Date: Tue, 22 Oct 2019 19:51:04 +0000 (+0200) Subject: [MOUNTMGR] Fix invalid WorkerReferences check in QueueWorkItem() X-Git-Tag: 0.4.14-RC~1446 X-Git-Url: https://git.reactos.org/?p=reactos.git;a=commitdiff_plain;h=457612702b615b45436f02bb8c7eda9be4d0c47c [MOUNTMGR] Fix invalid WorkerReferences check in QueueWorkItem() This fixes shutting down ReactOS under certain circumstances, where the references were incremented, but no worker thread started. Also, took the opportunity to clarify the WorkerReferences comparisons where relevant. CORE-16446 --- diff --git a/drivers/filters/mountmgr/database.c b/drivers/filters/mountmgr/database.c index a025f7db3ec..1cde41a995f 100644 --- a/drivers/filters/mountmgr/database.c +++ b/drivers/filters/mountmgr/database.c @@ -1268,8 +1268,8 @@ QueueWorkItem(IN PDEVICE_EXTENSION DeviceExtension, /* When called, lock is already acquired */ - /* If noone, start to work */ - if (InterlockedIncrement(&(DeviceExtension->WorkerReferences))) + /* If noone (-1 as references), start to work */ + if (InterlockedIncrement(&(DeviceExtension->WorkerReferences)) == 0) { IoQueueWorkItem(WorkItem->WorkItem, WorkerThread, DelayedWorkQueue, DeviceExtension); } diff --git a/drivers/filters/mountmgr/mountmgr.c b/drivers/filters/mountmgr/mountmgr.c index 37c85874c97..aa152621b51 100644 --- a/drivers/filters/mountmgr/mountmgr.c +++ b/drivers/filters/mountmgr/mountmgr.c @@ -822,7 +822,7 @@ MountMgrUnload(IN struct _DRIVER_OBJECT *DriverObject) KeInitializeEvent(&UnloadEvent, NotificationEvent, FALSE); /* Wait for workers to finish */ - if (InterlockedIncrement(&DeviceExtension->WorkerReferences)) + if (InterlockedIncrement(&DeviceExtension->WorkerReferences) > 0) { KeReleaseSemaphore(&(DeviceExtension->WorkerSemaphore), IO_NO_INCREMENT, 1, FALSE); @@ -1770,7 +1770,7 @@ MountMgrShutdown(IN PDEVICE_OBJECT DeviceObject, KeInitializeEvent(&UnloadEvent, NotificationEvent, FALSE); /* Wait for workers */ - if (InterlockedIncrement(&(DeviceExtension->WorkerReferences))) + if (InterlockedIncrement(&(DeviceExtension->WorkerReferences)) > 0) { KeReleaseSemaphore(&(DeviceExtension->WorkerSemaphore), IO_NO_INCREMENT,