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

git-svn-id: trunk@12761 -
This commit is contained in:
micha 2009-02-21 17:42:33 +00:00
parent ea52fee334
commit 3b171cb6fb

View File

@ -38,11 +38,6 @@ begin
end; } end; }
end; end;
end; end;
CM_DESTROYWINDOW:
begin
DestroyWindow(Window);
Result := 0;
end;
else else
Result := DefWindowProc(Window, AMessage, wParam, lParam); Result := DefWindowProc(Window, AMessage, wParam, lParam);
end; end;
@ -51,7 +46,7 @@ end;
const const
ThreadWindowClass: TWndClass = ( ThreadWindowClass: TWndClass = (
style: 0; style: 0;
lpfnWndProc: nil; lpfnWndProc: @ThreadWndProc;
cbClsExtra: 0; cbClsExtra: 0;
cbWndExtra: 0; cbWndExtra: 0;
hInstance: 0; hInstance: 0;
@ -69,7 +64,6 @@ procedure AddThread;
ClassRegistered: Boolean; ClassRegistered: Boolean;
begin begin
ThreadWindowClass.hInstance := HInstance; ThreadWindowClass.hInstance := HInstance;
ThreadWindowClass.lpfnWndProc:=WndProc(@ThreadWndProc);
ClassRegistered := GetClassInfo(HInstance, ThreadWindowClass.lpszClassName, ClassRegistered := GetClassInfo(HInstance, ThreadWindowClass.lpszClassName,
@TempClass); @TempClass);
if not ClassRegistered or (TempClass.lpfnWndProc <> WndProc(@ThreadWndProc)) then if not ClassRegistered or (TempClass.lpfnWndProc <> WndProc(@ThreadWndProc)) then
@ -90,8 +84,11 @@ end;
procedure RemoveThread; procedure RemoveThread;
begin 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 if InterlockedDecrement(ThreadCount)=0 then
PostMessage(ThreadWindow, CM_DESTROYWINDOW, 0, 0); DestroyWindow(ThreadWindow);
end; end;