BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

TCustomWinSocket.SendStreamPiece Leak?

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi Internet Winsock
View previous topic :: View next topic  
Author Message
Steve Zimmelman
Guest





PostPosted: Tue Sep 13, 2005 2:21 pm    Post subject: TCustomWinSocket.SendStreamPiece Leak? Reply with quote



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





PostPosted: Tue Sep 13, 2005 4:48 pm    Post subject: Re: TCustomWinSocket.SendStreamPiece Leak? Reply with quote




"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
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi Internet Winsock All times are GMT
Page 1 of 1

 
Jump to:  
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


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.