diff --git a/dokan/dokan.c b/dokan/dokan.c index 7feabe3b..a16fc70e 100644 --- a/dokan/dokan.c +++ b/dokan/dokan.c @@ -963,26 +963,26 @@ VOID CreateDispatchCommon(PDOKAN_IO_EVENT IoEvent, ULONG SizeOfEventInfo, BOOL U } VOID ReleaseDokanOpenInfo(PDOKAN_IO_EVENT IoEvent) { - LPWSTR fileNameForClose = NULL; - EnterCriticalSection(&IoEvent->DokanOpenInfo->CriticalSection); IoEvent->DokanOpenInfo->OpenCount--; - if (IoEvent->DokanOpenInfo->OpenCount < 1) { - if (IoEvent->DokanOpenInfo->FileName) { - fileNameForClose = IoEvent->DokanOpenInfo->FileName; - IoEvent->DokanOpenInfo->FileName = NULL; - } - LeaveCriticalSection(&IoEvent->DokanOpenInfo->CriticalSection); - PushFileOpenInfo(IoEvent->DokanOpenInfo); - IoEvent->DokanOpenInfo = NULL; - if (IoEvent->EventResult) { - // Reset the Kernel UserContext if we can. Close events do not have one. - IoEvent->EventResult->Context = 0; - } - } else { + if (IoEvent->DokanOpenInfo->OpenCount > 0) { LeaveCriticalSection(&IoEvent->DokanOpenInfo->CriticalSection); + return; } + LPWSTR fileNameForClose = NULL; + if (IoEvent->DokanOpenInfo->FileName) { + fileNameForClose = IoEvent->DokanOpenInfo->FileName; + IoEvent->DokanOpenInfo->FileName = NULL; + } + IoEvent->DokanFileInfo.Context =IoEvent->DokanOpenInfo->UserContext; + LeaveCriticalSection(&IoEvent->DokanOpenInfo->CriticalSection); + PushFileOpenInfo(IoEvent->DokanOpenInfo); + IoEvent->DokanOpenInfo = NULL; + if (IoEvent->EventResult) { + // Reset the Kernel UserContext if we can. Close events do not have one. + IoEvent->EventResult->Context = 0; + } if (fileNameForClose) { if (IoEvent->DokanInstance->DokanOperations->CloseFile) { IoEvent->DokanInstance->DokanOperations->CloseFile(