 |
BorlandTalk.com Borland discussion newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Steve Zimmelman Guest
|
Posted: Tue Sep 13, 2005 2:21 pm Post subject: TCustomWinSocket.SendStreamPiece Leak? |
|
|
There appears to be a possible leak in the SendStreamPiece method where
FSendStream will not get freed. It's in the section that traps the error.
See my comments below...
function TCustomWinSocket.SendStreamPiece: Boolean;
var
Buffer: array[0..4095] of Byte;
StartPos: Integer;
AmountInBuf: Integer;
AmountSent: Integer;
ErrorCode: Integer;
procedure DropStream;
begin
if FDropAfterSend then Disconnect(FSocket);
FDropAfterSend := False;
FSendStream.Free;
FSendStream := nil;
end;
begin
Lock;
try
Result := False;
if FSendStream <> nil then
begin
if (FSocket = INVALID_SOCKET) or (not FConnected) then exit;
while True do
begin
StartPos := FSendStream.Position;
AmountInBuf := FSendStream.Read(Buffer, SizeOf(Buffer));
if AmountInBuf > 0 then
begin
AmountSent := send(FSocket, Buffer, AmountInBuf, 0);
if AmountSent = SOCKET_ERROR then
begin
ErrorCode := WSAGetLastError;
if ErrorCode <> WSAEWOULDBLOCK then
begin
Error(Self, eeSend, ErrorCode);
Disconnect(FSocket);
DropStream;
if FAsyncStyles <> [] then Abort;
Break;
end else
begin
// ====== Suspect code here =======
FSendStream.Position := StartPos;
Break;
// =============================
When this break occurs, the Result of the method become true and FSendStream
is never freed.
end;
end else if AmountInBuf > AmountSent then
FSendStream.Position := StartPos + AmountSent
else if FSendStream.Position = FSendStream.Size then
begin
DropStream;
Break;
end;
end else
begin
DropStream;
Break;
end;
end;
Result := True;
end;
finally
Unlock;
end;
end;
Am I missing something, or is this an oversight?
TIA,
-Steve-
|
|
| Back to top |
|
 |
Remy Lebeau (TeamB) Guest
|
Posted: Tue Sep 13, 2005 4:48 pm Post subject: Re: TCustomWinSocket.SendStreamPiece Leak? |
|
|
"Steve Zimmelman" <skz (AT) charter (DOT) nospam.net> wrote
| Quote: | There appears to be a possible leak in the SendStreamPiece
method where FSendStream will not get freed.
|
That is a long-standing known problem. Don't use SendStream(). Send the
stream data manually via SendBuf() instead.
Gambit
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|