Handle leak in TInetSocket lazarus / 38-Networking and Web Programming ---------------------------------------------------------------------- Ludovic de Jouvencel · 2015-02-24 10:09 The code below is a little bit strange, i had never seen an exception raised from the constructor of a class, before reading open source code lol I also thought that "inherited create" should be the first line of the constructor method. Code: [Select]Constructor TInetSocket.Create(const AHost: String; APort: Word); Var   S : Longint; begin   FHost:=AHost;   FPort:=APort;   S:=fpSocket(AF_INET,SOCK_STREAM,0);   DoConnect(S);   Inherited Create(S); end; Procedure TInetSocket.DoConnect(ASocket : Longint); Var   A : THostAddr;   addr: TInetSockAddr; begin   A := StrToHostAddr(FHost);   if A.s_bytes[1] = 0 then     With THostResolver.Create(Nil) do       try         If Not NameLookup(FHost) then           raise ESocketError.Create(seHostNotFound, [FHost]);         A:=HostAddress;       finally         free;       end;   addr.sin_family := AF_INET;   addr.sin_port := ShortHostToNet(FPort);   addr.sin_addr.s_addr := HostToNet(a.s_addr);   If  Sockets.fpConnect(ASocket, @addr, sizeof(addr))<>0 then     raise ESocketError.Create(seConnectFailed, [Format('%s:%d',[FHost, FPort])]); end;  Could you explain to me where the socket handle is free if an ESocketError exception is raised (example "Connect to ... failed") ? ---------------------------------------------------------------------- marcov · 2015-02-24 10:30 No, but I can explain you where to file a bug :-) http://bugs.freepascal.org Probably a try except around doconnect it should free the handle on exception