Skip to content

Commit

Permalink
fix memory leak in Create and Close
Browse files Browse the repository at this point in the history
git-svn-id: http://dokan.googlecode.com/svn/trunk@151 53ea604a-054e-0410-8546-456bafaea6b0
  • Loading branch information
asakaw committed Jul 4, 2010
1 parent 88bd623 commit d5f80ab
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 3 deletions.
4 changes: 4 additions & 0 deletions sys/close.c
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,10 @@ Return Value:

if (eventContext == NULL) {
//status = STATUS_INSUFFICIENT_RESOURCES;
DDbgPrint(" eventContext == NULL\n");
DDbgPrint(" Free CCB:%X\n", ccb);
DokanFreeCCB(ccb);
DokanFreeFCB(fcb);
status = STATUS_SUCCESS;
__leave;
}
Expand Down
14 changes: 11 additions & 3 deletions sys/create.c
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ DokanAllocateFCB(
InitializeListHead(&fcb->NextCCB);
InsertTailList(&Vcb->NextFCB, &fcb->NextFCB);

InterlockedIncrement(&Vcb->FcbAllocated);

return fcb;
}

Expand Down Expand Up @@ -147,11 +149,10 @@ DokanGetFCB(
ExFreePool(FileName);
}

InterlockedIncrement(&fcb->FileCount);

ExReleaseResourceLite(&Vcb->Resource);
KeLeaveCriticalRegion();

InterlockedIncrement(&fcb->FileCount);
return fcb;
}

Expand Down Expand Up @@ -193,7 +194,8 @@ DokanFreeFCB(
ExDeleteResourceLite(&Fcb->Resource);
ExDeleteResourceLite(&Fcb->MainResource);
ExDeleteResourceLite(&Fcb->PagingIoResource);


InterlockedIncrement(&vcb->FcbFreed);
ExFreePool(Fcb);

} else {
Expand Down Expand Up @@ -243,6 +245,7 @@ DokanAllocateCCB(

ccb->MountId = Dcb->MountId;

InterlockedIncrement(&Fcb->Vcb->CcbAllocated);
return ccb;
}

Expand Down Expand Up @@ -274,6 +277,7 @@ DokanFreeCCB(
}

ExFreePool(ccb);
InterlockedIncrement(&fcb->Vcb->CcbFreed);

return STATUS_SUCCESS;
}
Expand Down Expand Up @@ -629,6 +633,10 @@ DokanCompleteCreate(
DokanNotifyReportChange(fcb, FILE_NOTIFY_CHANGE_FILE_NAME, FILE_ACTION_ADDED);
}
}
} else {
DDbgPrint(" IRP_MJ_CREATE failed. Free CCB:%X\n", ccb);
DokanFreeCCB(ccb);
DokanFreeFCB(fcb);
}

irp->IoStatus.Status = status;
Expand Down
5 changes: 5 additions & 0 deletions sys/dokan.h
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,11 @@ typedef struct _DokanVolumeControlBlock {
PNOTIFY_SYNC NotifySync;
LIST_ENTRY DirNotifyList;

ULONG FcbAllocated;
ULONG FcbFreed;
ULONG CcbAllocated;
ULONG CcbFreed;

} DokanVCB, *PDokanVCB;


Expand Down
5 changes: 5 additions & 0 deletions sys/init.c
Original file line number Diff line number Diff line change
Expand Up @@ -658,6 +658,11 @@ DokanDeleteDeviceObject(

//IoUnregisterFileSystem(vcb->DeviceObject);

DDbgPrint(" FCB allocated: %d\n", vcb->FcbAllocated);
DDbgPrint(" FCB freed: %d\n", vcb->FcbFreed);
DDbgPrint(" CCB allocated: %d\n", vcb->CcbAllocated);
DDbgPrint(" CCB freed: %d\n", vcb->CcbFreed);

// delete diskDeviceObject
DDbgPrint(" Delete DeviceObject\n");
IoDeleteDevice(vcb->DeviceObject);
Expand Down

0 comments on commit d5f80ab

Please sign in to comment.