mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-04-15 14:19:28 +02:00
* 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:
parent
ea52fee334
commit
3b171cb6fb
@ -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;
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user