Menu

#25 Crash when monitoring statements > 1000 bytes

open
nobody
5
2007-11-16
2007-11-16
B. Schulte
No

When a statement is detected with a text > 1000 bytes, the procedure TWriterThread.WriteToBuffer crashes because the message is deleted a second time by calling
Synchronize(RemoveFromList).
..
I changed the code to this:
----------------------
procedure TWriterThread.WriteToBuffer;
var
i, len: Integer;
Text: string;
begin
Lock;
try
{ If there are no monitors throw out the message
The alternative is to have messages queue up
until a monitor is ready.}

if FMonitorCount^ = 0 then
Synchronize(RemoveFromList)
else
begin
Text := TTraceObject(FMsgs[0]).FMsg;
i := 1;
len := Length(Text);
FTraceDataType^ := Integer(TTraceObject(FMsgs[0]).FDataType);
FTimeStamp^ := TTraceObject(FMsgs[0]).FTimeStamp;

try
while (len > 0) do begin
BeginWrite;
FBufferSize^ := Min(len, cMaxBufferSize);
Move(Text[i], FBuffer[0], FBufferSize^);
Inc(i, cMaxBufferSize);
Dec(len, cMaxBufferSize);
EndWrite;
end;
finally
{Do this in the main thread so the main thread
adds and deletes}
Synchronize(RemoveFromList);
end;
end;
finally
Unlock;
end;
end;

---------

Discussion


Log in to post a comment.

MongoDB Logo MongoDB