From 457612702b615b45436f02bb8c7eda9be4d0c47c Mon Sep 17 00:00:00 2001 From: Pierre Schweitzer Date: Tue, 22 Oct 2019 21:51:04 +0200 Subject: [PATCH] [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 --- drivers/filters/mountmgr/database.c | 4 ++-- drivers/filters/mountmgr/mountmgr.c | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) 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, -- 2.17.1