>From 5fbe0ef998b2285e105c9f1d9b273fca55b7d06f Mon Sep 17 00:00:00 2001
From: Alistair Leslie-Hughes <leslie_alistair@hotmail.com>
Date: Thu, 3 Nov 2011 09:35:06 +1100
Subject: [PATCH] Move clearing of processes to Terminate
To: wine-patches <wine-patches@winehq.org>

---
 dlls/mscoree/cordebug.c |   22 +++++++++++++---------
 1 files changed, 13 insertions(+), 9 deletions(-)

diff --git a/dlls/mscoree/cordebug.c b/dlls/mscoree/cordebug.c
index 8fe7501..ede137d 100644
--- a/dlls/mscoree/cordebug.c
+++ b/dlls/mscoree/cordebug.c
@@ -180,20 +180,13 @@ static ULONG WINAPI CorDebug_Release(ICorDebug *iface)
 {
     CorDebug *This = impl_from_ICorDebug( iface );
     ULONG ref = InterlockedDecrement(&This->ref);
-    struct CorProcess *cursor, *cursor2;
 
     TRACE("%p ref=%u\n", This, ref);
 
     if (ref == 0)
     {
-        LIST_FOR_EACH_ENTRY_SAFE(cursor, cursor2, &This->processes, struct CorProcess, entry)
-        {
-            if(cursor->pProcess)
-                ICorDebugProcess_Release(cursor->pProcess);
-
-            list_remove(&cursor->entry);
-            HeapFree(GetProcessHeap(), 0, cursor);
-        }
+        if(list_count(&This->processes) != 0)
+            ERR("Processes haven't been removed Correctly\n");
 
         if(This->runtimehost)
             ICLRRuntimeHost_Release(This->runtimehost);
@@ -220,8 +213,19 @@ static HRESULT WINAPI CorDebug_Initialize(ICorDebug *iface)
 
 static HRESULT WINAPI CorDebug_Terminate(ICorDebug *iface)
 {
+    struct CorProcess *cursor, *cursor2;
     CorDebug *This = impl_from_ICorDebug( iface );
     FIXME("stub %p\n", This);
+
+    LIST_FOR_EACH_ENTRY_SAFE(cursor, cursor2, &This->processes, struct CorProcess, entry)
+    {
+        if(cursor->pProcess)
+            ICorDebugProcess_Release(cursor->pProcess);
+
+        list_remove(&cursor->entry);
+        HeapFree(GetProcessHeap(), 0, cursor);
+    }
+
     return E_NOTIMPL;
 }
 
-- 
1.7.5.4

