mirror of
https://github.com/reactos/reactos.git
synced 2026-07-02 00:54:22 +08:00
Removed memory leaks
Fixed bug in console driver (wasn't completing irp) svn path=/trunk/; revision=194
This commit is contained in:
@@ -75,6 +75,7 @@ void ExecuteDir(char* cmdline)
|
||||
debug_printf("%s\n",FindData.cFileName);
|
||||
} while(FindNextFile(shandle,&FindData));
|
||||
debug_printf("\n %d files\n %d directories\n\n",nFile,nRep);
|
||||
FindClose(shandle);
|
||||
}
|
||||
|
||||
void ExecuteType(char* cmdline)
|
||||
@@ -99,6 +100,7 @@ void ExecuteType(char* cmdline)
|
||||
debug_printf("%c",c);
|
||||
c = 0;
|
||||
}
|
||||
CloseHandle(FileHandle);
|
||||
}
|
||||
|
||||
int ExecuteProcess(char* name, char* cmdline)
|
||||
|
||||
@@ -71,7 +71,7 @@ NTSTATUS ScrDispatch(PDEVICE_OBJECT DeviceObject, PIRP Irp)
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
IoCompleteRequest(Irp, Status);
|
||||
// DPRINT("Status %d\n",Status);
|
||||
return(Status);
|
||||
}
|
||||
|
||||
@@ -20,31 +20,45 @@
|
||||
NTSTATUS IoPrepareIrpBuffer(PIRP Irp,
|
||||
PDEVICE_OBJECT DeviceObject,
|
||||
PVOID Buffer,
|
||||
PVOID Length)
|
||||
ULONG Length,
|
||||
ULONG MajorFunction)
|
||||
/*
|
||||
* FUNCTION: Prepares the buffer to be used for an IRP
|
||||
*/
|
||||
{
|
||||
Irp->UserBuffer = (LPVOID)Buffer;
|
||||
if (DeviceObject->Flags&DO_BUFFERED_IO)
|
||||
Irp->UserBuffer = Buffer;
|
||||
if (DeviceObject->Flags & DO_BUFFERED_IO)
|
||||
{
|
||||
DPRINT("Doing buffer i/o\n",0);
|
||||
DPRINT("Doing buffer i/o\n");
|
||||
Irp->AssociatedIrp.SystemBuffer = (PVOID)
|
||||
ExAllocatePool(NonPagedPool,Length);
|
||||
ExAllocatePool(NonPagedPool,Length);
|
||||
if (Irp->AssociatedIrp.SystemBuffer==NULL)
|
||||
{
|
||||
return(STATUS_UNSUCCESSFUL);
|
||||
IoFreeIrp(Irp);
|
||||
return(NULL);
|
||||
}
|
||||
/* FIXME: should copy buffer in on other ops */
|
||||
if (MajorFunction == IRP_MJ_WRITE)
|
||||
{
|
||||
RtlCopyMemory(Irp->AssociatedIrp.SystemBuffer, Buffer, Length);
|
||||
}
|
||||
}
|
||||
if (DeviceObject->Flags&DO_DIRECT_IO)
|
||||
if (DeviceObject->Flags & DO_DIRECT_IO)
|
||||
{
|
||||
DPRINT("Doing direct i/o\n",0);
|
||||
DPRINT("Doing direct i/o\n");
|
||||
|
||||
Irp->MdlAddress = MmCreateMdl(NULL,Buffer,Length);
|
||||
MmProbeAndLockPages(Irp->MdlAddress,UserMode,IoWriteAccess);
|
||||
if (MajorFunction == IRP_MJ_READ)
|
||||
{
|
||||
MmProbeAndLockPages(Irp->MdlAddress,UserMode,IoWriteAccess);
|
||||
}
|
||||
else
|
||||
{
|
||||
MmProbeAndLockPages(Irp->MdlAddress,UserMode,IoReadAccess);
|
||||
}
|
||||
Irp->UserBuffer = NULL;
|
||||
Irp->AssociatedIrp.SystemBuffer = NULL;
|
||||
}
|
||||
}
|
||||
return(STATUS_SUCCESS);
|
||||
}
|
||||
|
||||
@@ -236,41 +250,8 @@ PIRP IoBuildSynchronousFsdRequest(ULONG MajorFunction,
|
||||
return(NULL);
|
||||
}
|
||||
|
||||
Irp->UserBuffer = (LPVOID)Buffer;
|
||||
Irp->UserEvent = Event;
|
||||
Irp->UserIosb = IoStatusBlock;
|
||||
if (DeviceObject->Flags & DO_BUFFERED_IO)
|
||||
{
|
||||
DPRINT("Doing buffer i/o\n");
|
||||
Irp->AssociatedIrp.SystemBuffer = (PVOID)
|
||||
ExAllocatePool(NonPagedPool,Length);
|
||||
if (Irp->AssociatedIrp.SystemBuffer==NULL)
|
||||
{
|
||||
IoFreeIrp(Irp);
|
||||
return(NULL);
|
||||
}
|
||||
/* FIXME: should copy buffer in on other ops */
|
||||
if (MajorFunction == IRP_MJ_WRITE)
|
||||
{
|
||||
RtlCopyMemory(Irp->AssociatedIrp.SystemBuffer, Buffer, Length);
|
||||
}
|
||||
}
|
||||
if (DeviceObject->Flags & DO_DIRECT_IO)
|
||||
{
|
||||
DPRINT("Doing direct i/o\n");
|
||||
|
||||
Irp->MdlAddress = MmCreateMdl(NULL,Buffer,Length);
|
||||
if (MajorFunction == IRP_MJ_READ)
|
||||
{
|
||||
MmProbeAndLockPages(Irp->MdlAddress,UserMode,IoWriteAccess);
|
||||
}
|
||||
else
|
||||
{
|
||||
MmProbeAndLockPages(Irp->MdlAddress,UserMode,IoReadAccess);
|
||||
}
|
||||
Irp->UserBuffer = NULL;
|
||||
Irp->AssociatedIrp.SystemBuffer = NULL;
|
||||
}
|
||||
|
||||
StackPtr = IoGetNextIrpStackLocation(Irp);
|
||||
StackPtr->MajorFunction = MajorFunction;
|
||||
@@ -280,14 +261,17 @@ PIRP IoBuildSynchronousFsdRequest(ULONG MajorFunction,
|
||||
StackPtr->DeviceObject = DeviceObject;
|
||||
StackPtr->FileObject = NULL;
|
||||
StackPtr->CompletionRoutine = NULL;
|
||||
StackPtr->Parameters.Write.Length = Length;
|
||||
|
||||
IoPrepareIrpBuffer(Irp,
|
||||
DeviceObject,
|
||||
Buffer,
|
||||
Length,
|
||||
MajorFunction);
|
||||
|
||||
if (MajorFunction == IRP_MJ_READ)
|
||||
{
|
||||
if (StartingOffset != NULL)
|
||||
{
|
||||
DPRINT("StartingOffset:%ld:%ld\n",
|
||||
GET_LARGE_INTEGER_HIGH_PART(*StartingOffset),
|
||||
GET_LARGE_INTEGER_LOW_PART(*StartingOffset));
|
||||
StackPtr->Parameters.Read.ByteOffset = *StartingOffset;
|
||||
}
|
||||
else
|
||||
@@ -297,6 +281,7 @@ PIRP IoBuildSynchronousFsdRequest(ULONG MajorFunction,
|
||||
SET_LARGE_INTEGER_HIGH_PART(StackPtr->Parameters.Read.ByteOffset,
|
||||
0);
|
||||
}
|
||||
StackPtr->Parameters.Read.Length = Length;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -311,6 +296,7 @@ PIRP IoBuildSynchronousFsdRequest(ULONG MajorFunction,
|
||||
SET_LARGE_INTEGER_HIGH_PART(StackPtr->Parameters.Write.ByteOffset,
|
||||
0);
|
||||
}
|
||||
StackPtr->Parameters.Write.Length = Length;
|
||||
}
|
||||
|
||||
return(Irp);
|
||||
|
||||
@@ -100,16 +100,19 @@ NTSTATUS ZwCreateFile(PHANDLE FileHandle,
|
||||
PIO_STACK_LOCATION StackLoc;
|
||||
PWSTR Remainder;
|
||||
|
||||
DPRINT("ZwCreateFile(FileHandle %x, DesiredAccess %x, "
|
||||
"ObjectAttributes %x ObjectAttributes->ObjectName->Buffer %w)\n",
|
||||
FileHandle,DesiredAccess,ObjectAttributes,
|
||||
ObjectAttributes->ObjectName->Buffer);
|
||||
DbgPrint("ZwCreateFile(FileHandle %x, DesiredAccess %x, "
|
||||
"ObjectAttributes %x ObjectAttributes->ObjectName->Buffer %w)\n",
|
||||
FileHandle,DesiredAccess,ObjectAttributes,
|
||||
ObjectAttributes->ObjectName->Buffer);
|
||||
|
||||
assert_irql(PASSIVE_LEVEL);
|
||||
|
||||
*FileHandle=0;
|
||||
|
||||
FileObject = ObGenericCreateObject(FileHandle,DesiredAccess,NULL,IoFileType);
|
||||
FileObject = ObGenericCreateObject(FileHandle,
|
||||
DesiredAccess,
|
||||
NULL,
|
||||
IoFileType);
|
||||
memset(FileObject,0,sizeof(FILE_OBJECT));
|
||||
|
||||
Status = ObOpenObjectByName(ObjectAttributes,&Object,&Remainder);
|
||||
|
||||
@@ -179,10 +179,7 @@ NTSTATUS STDCALL ZwQueryDirectoryFile(
|
||||
}
|
||||
if (ReturnSingleEntry)
|
||||
{
|
||||
DPRINT("Setting ReturingSingleEntry flag\n");
|
||||
IoStack->Flags = IoStack->Flags | SL_RETURN_SINGLE_ENTRY;
|
||||
DPRINT("SL_RETURN_SINGLE_ENTRY %x\n",SL_RETURN_SINGLE_ENTRY);
|
||||
DPRINT("IoStack->Flags %x\n",IoStack->Flags);
|
||||
}
|
||||
if (((PFILE_DIRECTORY_INFORMATION)FileInformation)->FileIndex != 0)
|
||||
{
|
||||
|
||||
@@ -160,26 +160,20 @@ PIO_STACK_LOCATION IoGetNextIrpStackLocation(PIRP Irp)
|
||||
return(&Irp->Stack[Irp->CurrentLocation-1]);
|
||||
}
|
||||
|
||||
NTSTATUS IoCallDriver(PDEVICE_OBJECT DevObject, PIRP irp)
|
||||
NTSTATUS IoCallDriver(PDEVICE_OBJECT DeviceObject, PIRP Irp)
|
||||
/*
|
||||
* FUNCTION: Sends an IRP to the next lower driver
|
||||
*/
|
||||
{
|
||||
NTSTATUS Status;
|
||||
PDRIVER_OBJECT drv = DevObject->DriverObject;
|
||||
IO_STACK_LOCATION* param = IoGetNextIrpStackLocation(irp);
|
||||
PDRIVER_OBJECT DriverObject = DeviceObject->DriverObject;
|
||||
PIO_STACK_LOCATION param = IoGetNextIrpStackLocation(Irp);
|
||||
|
||||
DPRINT("Deviceobject %x\n",DevObject);
|
||||
DPRINT("Irp %x\n",irp);
|
||||
Irp->Tail.Overlay.CurrentStackLocation--;
|
||||
Irp->CurrentLocation--;
|
||||
|
||||
irp->Tail.Overlay.CurrentStackLocation--;
|
||||
irp->CurrentLocation--;
|
||||
|
||||
DPRINT("Io stack address %x\n",param);
|
||||
DPRINT("Function %d Routine %x\n",param->MajorFunction,
|
||||
drv->MajorFunction[param->MajorFunction]);
|
||||
|
||||
Status = drv->MajorFunction[param->MajorFunction](DevObject,irp);
|
||||
Status = DriverObject->MajorFunction[param->MajorFunction](DeviceObject,
|
||||
Irp);
|
||||
return Status;
|
||||
}
|
||||
|
||||
@@ -193,11 +187,13 @@ PIRP IoAllocateIrp(CCHAR StackSize, BOOLEAN ChargeQuota)
|
||||
*/
|
||||
{
|
||||
PIRP Irp;
|
||||
|
||||
|
||||
#if 0
|
||||
DbgPrint("IoAllocateIrp(StackSize %d ChargeQuota %d)\n",
|
||||
StackSize,
|
||||
ChargeQuota);
|
||||
KeDumpStackFrames(0,8);
|
||||
#endif
|
||||
|
||||
if (ChargeQuota)
|
||||
{
|
||||
@@ -269,13 +265,10 @@ VOID IoCompleteRequest(PIRP Irp, CCHAR PriorityBoost)
|
||||
NTSTATUS Status;
|
||||
|
||||
DPRINT("IoCompleteRequest(Irp %x, PriorityBoost %d)\n",
|
||||
Irp,PriorityBoost);
|
||||
Irp,PriorityBoost);
|
||||
|
||||
for (i=0;i<Irp->StackCount;i++)
|
||||
{
|
||||
DPRINT("&Irp->Stack[%d].CompletionRoutine %08lx\n",
|
||||
i,
|
||||
Irp->Stack[i].CompletionRoutine);
|
||||
if (Irp->Stack[i].CompletionRoutine != NULL)
|
||||
{
|
||||
Status = Irp->Stack[i].CompletionRoutine(
|
||||
@@ -287,10 +280,8 @@ VOID IoCompleteRequest(PIRP Irp, CCHAR PriorityBoost)
|
||||
return;
|
||||
}
|
||||
}
|
||||
DPRINT("Irp->Stack[%d].Control %08lx\n", i, Irp->Stack[i].Control);
|
||||
if (Irp->Stack[i].Control & SL_PENDING_RETURNED)
|
||||
{
|
||||
DPRINT("Setting PendingReturned flag\n");
|
||||
Irp->PendingReturned = TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
* PROJECT: ReactOS kernel
|
||||
* FILE: ntoskrnl/io/rw.c
|
||||
* PURPOSE: Implements read/write APIs
|
||||
* PROGRAMMER: David Welch (welch@mcmail.com)
|
||||
* PROGRAMMER: David Welch (welch@cwcom.net)
|
||||
* UPDATE HISTORY:
|
||||
* 30/05/98: Created
|
||||
*/
|
||||
@@ -72,11 +72,8 @@ NTSTATUS ZwReadFile(HANDLE FileHandle,
|
||||
NULL);
|
||||
if (Status != STATUS_SUCCESS)
|
||||
{
|
||||
DPRINT("ZwReadFile() =");
|
||||
// DbgPrintErrorMessage(Status);
|
||||
return(Status);
|
||||
}
|
||||
assert(FileObject != NULL);
|
||||
|
||||
if (ByteOffset==NULL)
|
||||
{
|
||||
@@ -110,6 +107,7 @@ NTSTATUS ZwReadFile(HANDLE FileHandle,
|
||||
KeWaitForSingleObject(&Event,Executive,KernelMode,FALSE,NULL);
|
||||
return(IoStatusBlock->Status);
|
||||
}
|
||||
ObDereferenceObject(FileObject);
|
||||
return(Status);
|
||||
}
|
||||
|
||||
@@ -176,16 +174,6 @@ NTSTATUS ZwWriteFile(HANDLE FileHandle,
|
||||
DPRINT("FileObject->DeviceObject %x\n",FileObject->DeviceObject);
|
||||
StackPtr = IoGetNextIrpStackLocation(Irp);
|
||||
StackPtr->FileObject = FileObject;
|
||||
StackPtr->Parameters.Write.Length = Length;
|
||||
if (ByteOffset!=NULL)
|
||||
{
|
||||
StackPtr->Parameters.Write.ByteOffset = *ByteOffset;
|
||||
}
|
||||
else
|
||||
{
|
||||
SET_LARGE_INTEGER_LOW_PART(StackPtr->Parameters.Write.ByteOffset, 0);
|
||||
SET_LARGE_INTEGER_HIGH_PART(StackPtr->Parameters.Write.ByteOffset, 0);
|
||||
}
|
||||
if (Key!=NULL)
|
||||
{
|
||||
StackPtr->Parameters.Write.Key = *Key;
|
||||
@@ -200,7 +188,8 @@ NTSTATUS ZwWriteFile(HANDLE FileHandle,
|
||||
KeWaitForSingleObject(&Event,Executive,KernelMode,FALSE,NULL);
|
||||
Status = Irp->IoStatus.Status;
|
||||
}
|
||||
|
||||
ObDereferenceObject(FileObject);
|
||||
|
||||
return(Status);
|
||||
}
|
||||
|
||||
|
||||
@@ -532,7 +532,7 @@ BOOLEAN KiTimerInterrupt(VOID)
|
||||
}
|
||||
// sprintf(str,"%.8u %.8u",EiFreeNonPagedPool,ticks);
|
||||
memset(str, 0, sizeof(str));
|
||||
sprintf(str,"%.8u %.8u",EiNrUsedBlocks,KiTimerTicks);
|
||||
sprintf(str,"%.8u %.8u",EiNrUsedBlocks,EiFreeNonPagedPool);
|
||||
// sprintf(str,"%.8u %.8u",EiFreeNonPagedPool,EiUsedNonPagedPool);
|
||||
// sprintf(str,"%.8u %.8u",PiNrThreads,KiTimerTicks);
|
||||
for (i=0;i<17;i++)
|
||||
|
||||
@@ -1037,7 +1037,8 @@ LdrProcessPEImage(HANDLE ProcessHandle,
|
||||
PIMAGE_NT_HEADERS NTHeaders;
|
||||
PMODULE Module;
|
||||
LARGE_INTEGER SectionOffset;
|
||||
|
||||
HANDLE SectionHandle;
|
||||
|
||||
/* Allocate memory for headers */
|
||||
Module = HEADER_TO_BODY(ModuleHandle);
|
||||
if (Module == NULL)
|
||||
|
||||
@@ -34,7 +34,7 @@
|
||||
#define VALIDATE_POOL
|
||||
#endif
|
||||
|
||||
#if 1
|
||||
#if 0
|
||||
#define POOL_TRACE(args...) do { DbgPrint(args); } while(0);
|
||||
#else
|
||||
#define POOL_TRACE(args...)
|
||||
|
||||
@@ -455,7 +455,6 @@ NTSTATUS STDCALL ZwFreeVirtualMemory(IN HANDLE ProcessHandle,
|
||||
NULL);
|
||||
if (Status != STATUS_SUCCESS)
|
||||
{
|
||||
DbgPrint("ZwFreeVirtualMemory() = %x\n",Status);
|
||||
return(Status);
|
||||
}
|
||||
|
||||
@@ -465,8 +464,9 @@ NTSTATUS STDCALL ZwFreeVirtualMemory(IN HANDLE ProcessHandle,
|
||||
return(STATUS_UNSUCCESSFUL);
|
||||
}
|
||||
|
||||
if (FreeType == MEM_RELEASE)
|
||||
switch (FreeType)
|
||||
{
|
||||
case MEM_RELEASE:
|
||||
if (MemoryArea->BaseAddress != (*BaseAddress))
|
||||
{
|
||||
return(STATUS_UNSUCCESSFUL);
|
||||
@@ -476,9 +476,18 @@ NTSTATUS STDCALL ZwFreeVirtualMemory(IN HANDLE ProcessHandle,
|
||||
0,
|
||||
TRUE);
|
||||
return(STATUS_SUCCESS);
|
||||
|
||||
case MEM_DECOMMIT:
|
||||
MmSplitMemoryArea(PsGetCurrentProcess(),
|
||||
MemoryArea,
|
||||
*BaseAddress,
|
||||
*RegionSize,
|
||||
MEMORY_AREA_RESERVE,
|
||||
MemoryArea->Attributes);
|
||||
return(STATUS_SUCCESS);
|
||||
}
|
||||
|
||||
UNIMPLEMENTED;
|
||||
return(STATUS_NOT_IMPLEMENTED);
|
||||
}
|
||||
|
||||
NTSTATUS STDCALL NtLockVirtualMemory(HANDLE ProcessHandle,
|
||||
|
||||
@@ -432,12 +432,11 @@ VOID ObCreateEntry(PDIRECTORY_OBJECT parent,POBJECT_HEADER Object)
|
||||
InsertTailList(&parent->head,&Object->Entry);
|
||||
}
|
||||
|
||||
NTSTATUS
|
||||
ObLookupObject(HANDLE rootdir,
|
||||
PWSTR string,
|
||||
PVOID* Object,
|
||||
PWSTR* UnparsedSection,
|
||||
ULONG Attributes)
|
||||
NTSTATUS ObLookupObject(HANDLE rootdir,
|
||||
PWSTR string,
|
||||
PVOID* Object,
|
||||
PWSTR* UnparsedSection,
|
||||
ULONG Attributes)
|
||||
/*
|
||||
* FUNCTION: Lookup an object within the system namespc
|
||||
* ARGUMENTS:
|
||||
@@ -550,7 +549,8 @@ ObLookupObject(HANDLE rootdir,
|
||||
current_dir = BODY_TO_HEADER(current_dir)->ObjectType->
|
||||
Parse(current_dir,
|
||||
UnparsedSection);
|
||||
Status = (current_dir != NULL) ? STATUS_SUCCESS : STATUS_UNSUCCESSFUL;
|
||||
Status = (current_dir != NULL) ? STATUS_SUCCESS :
|
||||
STATUS_UNSUCCESSFUL;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user