Skip to content

Commit 2646391

Browse files
committed
Library - Fix incorrect lock used for DokanOpenInfo increment
1 parent bed6c5c commit 2646391

File tree

1 file changed

+17
-15
lines changed

1 file changed

+17
-15
lines changed

dokan/dokan.c

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -272,9 +272,9 @@ VOID SetupIOEventForProcessing(PDOKAN_IO_EVENT IoEvent) {
272272
IoEvent->DokanFileInfo.DokanOptions = IoEvent->DokanInstance->DokanOptions;
273273

274274
if (IoEvent->DokanOpenInfo) {
275-
EnterCriticalSection(&IoEvent->DokanInstance->CriticalSection);
275+
EnterCriticalSection(&IoEvent->DokanOpenInfo->CriticalSection);
276276
IoEvent->DokanOpenInfo->OpenCount++;
277-
LeaveCriticalSection(&IoEvent->DokanInstance->CriticalSection);
277+
LeaveCriticalSection(&IoEvent->DokanOpenInfo->CriticalSection);
278278
IoEvent->DokanFileInfo.Context =
279279
InterlockedAdd64(&IoEvent->DokanOpenInfo->UserContext, 0);
280280
IoEvent->DokanFileInfo.IsDirectory =
@@ -865,20 +865,22 @@ VOID CreateDispatchCommon(PDOKAN_IO_EVENT IoEvent, ULONG SizeOfEventInfo) {
865865
VOID ReleaseDokanOpenInfo(PDOKAN_IO_EVENT IoEvent) {
866866
LPWSTR fileNameForClose = NULL;
867867

868-
if (IoEvent->DokanOpenInfo != NULL) {
869-
EnterCriticalSection(&IoEvent->DokanOpenInfo->CriticalSection);
870-
IoEvent->DokanOpenInfo->OpenCount--;
871-
if (IoEvent->DokanOpenInfo->OpenCount < 1) {
872-
if (IoEvent->DokanOpenInfo->FileName) {
873-
fileNameForClose = IoEvent->DokanOpenInfo->FileName;
874-
IoEvent->DokanOpenInfo->FileName = NULL;
875-
}
876-
LeaveCriticalSection(&IoEvent->DokanOpenInfo->CriticalSection);
877-
PushFileOpenInfo(IoEvent->DokanOpenInfo);
878-
IoEvent->DokanOpenInfo = NULL;
879-
} else {
880-
LeaveCriticalSection(&IoEvent->DokanOpenInfo->CriticalSection);
868+
EnterCriticalSection(&IoEvent->DokanOpenInfo->CriticalSection);
869+
IoEvent->DokanOpenInfo->OpenCount--;
870+
if (IoEvent->DokanOpenInfo->OpenCount < 1) {
871+
if (IoEvent->DokanOpenInfo->FileName) {
872+
fileNameForClose = IoEvent->DokanOpenInfo->FileName;
873+
IoEvent->DokanOpenInfo->FileName = NULL;
874+
}
875+
LeaveCriticalSection(&IoEvent->DokanOpenInfo->CriticalSection);
876+
PushFileOpenInfo(IoEvent->DokanOpenInfo);
877+
IoEvent->DokanOpenInfo = NULL;
878+
if (IoEvent->EventResult) {
879+
// Reset the Kernel UserContext if we can. Close events do not have one.
880+
IoEvent->EventResult->Context = 0;
881881
}
882+
} else {
883+
LeaveCriticalSection(&IoEvent->DokanOpenInfo->CriticalSection);
882884
}
883885

884886
if (fileNameForClose) {

0 commit comments

Comments
 (0)