2013/5/3 Zaher Dirkey <parm...@gmail.com>

>
> On Fri, May 3, 2013 at 6:57 PM, silvioprog <silviop...@gmail.com> wrote:
>
>> when I close the server with one or more clients connected, I got a
>> memory leak.
>
>
> Check if the thread freed?
> Try to stop server manually (by button or in Close event in the form)
>
> Best Regards
> Zaher Dirkey
>

Yes, I already do it.

Now I'm trying to terminate all unterminated clients:

destructor TTcpIpServerSocketThread.Destroy;
begin
  DoTerminateClients;
  FClients.Free;
  FSocket.Free;
  inherited Destroy;
end;

....

procedure TTcpIpServerSocketThread.DoTerminateClients;
var
  VClients: TList;
  VClient: Pointer;
  VThread: TTcpIpServerClientThread;
begin
  VClients := FClients.LockList;
  try
    for VClient in VClients do
    begin
      VThread := TTcpIpServerClientThread(VClient);
      if Assigned(VThread) and not VThread.Finished then
      begin
        VThread.FreeOnTerminate := False;
        VThread.Terminate;
        FreeAndNil(VThread.FClientSocket);
        VThread.WaitFor;
        FreeAndNil(VThread);
      end;
    end;
  finally
    FClients.UnlockList;
  end;
end;

I'm testing it, on Windows it worked fine, I'll test on Linux now...

-- 
Silvio Clécio
My public projects - github.com/silvioprog
_______________________________________________
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal

Reply via email to