Author: sginsberg
Date: Tue Jan 13 18:34:24 2009
New Revision: 38751
URL:
http://svn.reactos.org/svn/reactos?rev=38751&view=rev
Log:
- KDBG: Correct the use of PsLookupThread/ProcessByThread/ProcessId -- the caller must
dereference the Thread/Process after use
Modified:
trunk/reactos/ntoskrnl/kdbg/kdb.c
trunk/reactos/ntoskrnl/kdbg/kdb_cli.c
Modified: trunk/reactos/ntoskrnl/kdbg/kdb.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/kdbg/kdb.c?rev=38…
==============================================================================
--- trunk/reactos/ntoskrnl/kdbg/kdb.c [iso-8859-1] (original)
+++ trunk/reactos/ntoskrnl/kdbg/kdb.c [iso-8859-1] Tue Jan 13 18:34:24 2009
@@ -1082,6 +1082,7 @@
if (KeIsExecutingDpc() && Process != KdbCurrentProcess)
{
KdbpPrint("Cannot attach to thread within another process while executing a
DPC.\n");
+ ObDereferenceObject(Thread);
return FALSE;
}
@@ -1130,6 +1131,7 @@
KdbCurrentProcess = Process;
}
+ ObDereferenceObject(Thread);
return TRUE;
}
@@ -1158,6 +1160,7 @@
}
Entry = Process->ThreadListHead.Flink;
+ ObDereferenceObject(Process);
if (Entry == &KdbCurrentProcess->ThreadListHead)
{
KdbpPrint("No threads in process 0x%08x, cannot attach to process!\n",
(ULONG)ProcessId);
Modified: trunk/reactos/ntoskrnl/kdbg/kdb_cli.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/kdbg/kdb_cli.c?re…
==============================================================================
--- trunk/reactos/ntoskrnl/kdbg/kdb_cli.c [iso-8859-1] (original)
+++ trunk/reactos/ntoskrnl/kdbg/kdb_cli.c [iso-8859-1] Tue Jan 13 18:34:24 2009
@@ -1090,6 +1090,7 @@
PLIST_ENTRY Entry;
PETHREAD Thread = NULL;
PEPROCESS Process = NULL;
+ BOOLEAN ReferencedThread = FALSE, ReferencedProcess = FALSE;
PULONG Esp;
PULONG Ebp;
ULONG Eip;
@@ -1118,6 +1119,9 @@
KdbpPrint("thread: Invalid process id!\n");
return TRUE;
}
+
+ /* Remember our reference */
+ ReferencedProcess = TRUE;
}
Entry = Process->ThreadListHead.Flink;
@@ -1127,6 +1131,7 @@
KdbpPrint("No threads in process 0x%08x!\n", ul);
else
KdbpPrint("No threads in current process!\n");
+ if (ReferencedProcess) ObDereferenceObject(Process);
return TRUE;
}
@@ -1181,6 +1186,9 @@
Entry = Entry->Flink;
}
while (Entry != &Process->ThreadListHead);
+
+ /* Release our reference, if any */
+ if (ReferencedProcess) ObDereferenceObject(Process);
}
else if (Argc >= 2 && _stricmp(Argv[1], "attach") == 0)
{
@@ -1219,6 +1227,9 @@
KdbpPrint("thread: Invalid thread id!\n");
return TRUE;
}
+
+ /* Remember our reference */
+ ReferencedThread = TRUE;
}
if (Thread->Tcb.State < (DeferredReady + 1))
@@ -1248,6 +1259,8 @@
Thread->Tcb.TrapFrame,
NPX_STATE_TO_STRING(Thread->Tcb.NpxState), Thread->Tcb.NpxState);
+ /* Release our reference if we had one */
+ if (ReferencedThread) ObDereferenceObject(Thread);
}
return TRUE;
@@ -1260,6 +1273,7 @@
{
PLIST_ENTRY Entry;
PEPROCESS Process;
+ BOOLEAN ReferencedProcess = FALSE;
PCHAR State, pend, str1, str2;
ULONG ul;
extern LIST_ENTRY PsActiveProcessHead;
@@ -1341,6 +1355,9 @@
KdbpPrint("proc: Invalid process id!\n");
return TRUE;
}
+
+ /* Remember our reference */
+ ReferencedProcess = TRUE;
}
State = ((Process->Pcb.State == ProcessInMemory) ? "In Memory" :
@@ -1353,6 +1370,9 @@
Process->UniqueProcessId,
State, Process->Pcb.State,
Process->ImageFileName);
+
+ /* Release our reference, if any */
+ if (ReferencedProcess) ObDereferenceObject(Process);
}
return TRUE;