Skip to content

Commit

Permalink
Library - Fix incorrect lock used for DokanOpenInfo increment
Browse files Browse the repository at this point in the history
  • Loading branch information
Liryna committed Feb 5, 2022
1 parent bed6c5c commit 2646391
Showing 1 changed file with 17 additions and 15 deletions.
32 changes: 17 additions & 15 deletions dokan/dokan.c
Original file line number Diff line number Diff line change
Expand Up @@ -272,9 +272,9 @@ VOID SetupIOEventForProcessing(PDOKAN_IO_EVENT IoEvent) {
IoEvent->DokanFileInfo.DokanOptions = IoEvent->DokanInstance->DokanOptions;

if (IoEvent->DokanOpenInfo) {
EnterCriticalSection(&IoEvent->DokanInstance->CriticalSection);
EnterCriticalSection(&IoEvent->DokanOpenInfo->CriticalSection);
IoEvent->DokanOpenInfo->OpenCount++;
LeaveCriticalSection(&IoEvent->DokanInstance->CriticalSection);
LeaveCriticalSection(&IoEvent->DokanOpenInfo->CriticalSection);
IoEvent->DokanFileInfo.Context =
InterlockedAdd64(&IoEvent->DokanOpenInfo->UserContext, 0);
IoEvent->DokanFileInfo.IsDirectory =
Expand Down Expand Up @@ -865,20 +865,22 @@ VOID CreateDispatchCommon(PDOKAN_IO_EVENT IoEvent, ULONG SizeOfEventInfo) {
VOID ReleaseDokanOpenInfo(PDOKAN_IO_EVENT IoEvent) {
LPWSTR fileNameForClose = NULL;

if (IoEvent->DokanOpenInfo != 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;
} else {
LeaveCriticalSection(&IoEvent->DokanOpenInfo->CriticalSection);
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 {
LeaveCriticalSection(&IoEvent->DokanOpenInfo->CriticalSection);
}

if (fileNameForClose) {
Expand Down

0 comments on commit 2646391

Please sign in to comment.