[CSRSRV]
authorTimo Kreuzer <timo.kreuzer@reactos.org>
Fri, 18 Feb 2011 15:01:00 +0000 (15:01 +0000)
committerTimo Kreuzer <timo.kreuzer@reactos.org>
Fri, 18 Feb 2011 15:01:00 +0000 (15:01 +0000)
Dereference all threads, when a process is terminated. Fixes ghost processes in taskmgr! Patch by Rafal Harabien, <rafalh1992 AT o2 DOT pl>

See issue #1567 for more details.

svn path=/trunk/; revision=50803

reactos/subsystems/win32/csrss/csrsrv/api/process.c

index 8b7a483..58fb959 100644 (file)
@@ -145,6 +145,8 @@ NTSTATUS WINAPI CsrFreeProcessData(HANDLE Pid)
   ULONG hash;
   PCSRSS_PROCESS_DATA pProcessData, *pPrevLink;
   HANDLE Process;
+  PLIST_ENTRY NextEntry;
+  PCSR_THREAD Thread;
 
   hash = ((ULONG_PTR)Pid >> 2) % (sizeof(ProcessData) / sizeof(*ProcessData));
   pPrevLink = &ProcessData[hash];
@@ -161,14 +163,27 @@ NTSTATUS WINAPI CsrFreeProcessData(HANDLE Pid)
       DPRINT("CsrFreeProcessData pid: %d\n", Pid);
       Process = pProcessData->Process;
       CallProcessDeleted(pProcessData);
+
+      /* Dereference all process threads */
+      NextEntry = pProcessData->ThreadList.Flink;
+      while (NextEntry != &pProcessData->ThreadList)
+      {
+        Thread = CONTAINING_RECORD(NextEntry, CSR_THREAD, Link);
+        NextEntry = NextEntry->Flink;
+
+        CsrThreadRefcountZero(Thread);
+      }
+
       if (pProcessData->CsrSectionViewBase)
         {
           NtUnmapViewOfSection(NtCurrentProcess(), pProcessData->CsrSectionViewBase);
         }
+
       if (pProcessData->ServerCommunicationPort)
         {
           NtClose(pProcessData->ServerCommunicationPort);
         }
+
       *pPrevLink = pProcessData->next;
 
       RtlFreeHeap(CsrssApiHeap, 0, pProcessData);