Skip to content

Find Bug from tncLine.pas #42

@jiangwei7480

Description

@jiangwei7480

hello:
I found a bug in the DestroyHandle function of the TncLine class, as shown in the following code:
delphi
procedure TncLine.DestroyHandle;
begin
if FActive then
begin
try
{$IFDEF MSWINDOWS}
Shutdown(FHandle, SD_BOTH);
CloseSocket(FHandle);
{$ELSE}
Shutdown(FHandle, SHUT_RDWR);
Posix.Unistd.__Close(FHandle);
{$ENDIF}
except
end;
try
SetDisconnected;
except
end;

FHandle := InvalidSocket;

end;
end;
When connecting to a service that is not running, the connection fails and triggers repeated reconnection attempts due to timeout, which will cause the socket buffer to freeze. The root cause is the if FActive then condition check inside the DestroyHandle function: the connection has not been successfully established at this point, so the created socket handle is not released.
I have edit it, It is:
try
{$IFDEF MSWINDOWS}
Shutdown(FHandle, SD_BOTH);
CloseSocket(FHandle);
{$ELSE}
Shutdown(FHandle, SHUT_RDWR);
Posix.Unistd.__Close(FHandle);
{$ENDIF}
except
end;
Try
try
if FActive then SetDisconnected;
except
end;
finally
FHandle := InvalidSocket;
end;

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions