Jelajahi Sumber

* windows rtl: fix resource leak when cleaning up last tthread without message loop (fixes issue #13173)

git-svn-id: trunk@12761 -
micha 16 tahun lalu
induk
melakukan
3b171cb6fb
1 mengubah file dengan 5 tambahan dan 8 penghapusan
  1. 5 8
      rtl/win/tthread.inc

+ 5 - 8
rtl/win/tthread.inc

@@ -38,11 +38,6 @@ begin
           end; }
         end;
       end;
-    CM_DESTROYWINDOW:
-      begin
-        DestroyWindow(Window);
-        Result := 0;
-      end;
   else
     Result := DefWindowProc(Window, AMessage, wParam, lParam);
   end;
@@ -51,7 +46,7 @@ end;
 const
   ThreadWindowClass: TWndClass = (
     style: 0;
-    lpfnWndProc: nil;
+    lpfnWndProc: @ThreadWndProc;
     cbClsExtra: 0;
     cbWndExtra: 0;
     hInstance: 0;
@@ -69,7 +64,6 @@ procedure AddThread;
     ClassRegistered: Boolean;
   begin
     ThreadWindowClass.hInstance := HInstance;
-    ThreadWindowClass.lpfnWndProc:=WndProc(@ThreadWndProc);
     ClassRegistered := GetClassInfo(HInstance, ThreadWindowClass.lpszClassName,
       @TempClass);
     if not ClassRegistered or (TempClass.lpfnWndProc <> WndProc(@ThreadWndProc)) then
@@ -90,8 +84,11 @@ end;
 
 procedure RemoveThread;
 begin
+  { note that when thread count reaches 0 we must be in main thread context }
+  { windows may only be destroyed in same thread as created in }
+  { posting a message to window thread does not work when we have no message loop }
   if InterlockedDecrement(ThreadCount)=0 then
-    PostMessage(ThreadWindow, CM_DESTROYWINDOW, 0, 0);
+    DestroyWindow(ThreadWindow);
 end;