From 5c2a9a991e2830467e2b34d0d54ac5d75dc391bb Mon Sep 17 00:00:00 2001 From: Simon Rozman Date: Sat, 8 Jun 2019 06:40:32 +0200 Subject: [PATCH] Refactor IRP_MJ_CLOSE TransitionLock unlocking Signed-off-by: Simon Rozman --- wintun.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/wintun.c b/wintun.c index 828f4da..b0be438 100644 --- a/wintun.c +++ b/wintun.c @@ -854,13 +854,13 @@ static NTSTATUS TunDispatch(DEVICE_OBJECT *DeviceObject, IRP *Irp) case IRP_MJ_CLOSE: irql = ExAcquireSpinLockExclusive(&ctx->TransitionLock); ASSERT(InterlockedGet64(&ctx->Device.RefCount) > 0); - if (InterlockedDecrement64(&ctx->Device.RefCount) <= 0) { - ExReleaseSpinLockExclusive(&ctx->TransitionLock, irql); + BOOLEAN last_handle = InterlockedDecrement64(&ctx->Device.RefCount) <= 0; + ExReleaseSpinLockExclusive(&ctx->TransitionLock, irql); + if (last_handle) { if (ctx->MiniportAdapterHandle) TunIndicateStatus(ctx->MiniportAdapterHandle, MediaConnectStateDisconnected); TunQueueClear(ctx, NDIS_STATUS_SEND_ABORTED); - } else - ExReleaseSpinLockExclusive(&ctx->TransitionLock, irql); + } IoReleaseRemoveLock(&ctx->Device.RemoveLock, stack->FileObject); status = STATUS_SUCCESS;