Error 161 raised in intBasicEventCreate in RTL (serious issue)
Original Reporter info from Mantis: snorkel
-
Reporter name:
Original Reporter info from Mantis: snorkel
- Reporter name:
Description:
Calling getlasterror right after a call to TEventObject.create in a very busy system such as a FTP server or SFTP server with the name property set to blank
causes a Error code 161 (The specified path is invalid.)
I reported this on the FPC mailing list and Sven was able to determine the issue is a null character #0 is being used in the RTL when name is blank.
Svens response from mailing list:
Are you able to compile FPC and its RTL yourself? In that case I'd like to ask you to adjust the function intBasicEventCreate in $fpcdir/rtl/win/systhrd.inc like this:
var
n: PChar;
begin
new(plocaleventrec(result));
if Length(Name) = 0 then
n := Nil
else
n := PChar(Name);
plocaleventrec(result)^.FHandle := CreateEvent(EventAttributes, AManualReset, InitialState, n);
end;
I rebuilt the RTL with Sven's fix and the error went away.
Steps to reproduce:
Call teventobject.create in a thread for reading and writing data for a socket for example on a FTP or SFTP server where the unamed teventobject.create gets called many many times.
Any other calls in the RLT that use createevent with pchar(name) for the name param should also be checked.
Additional information:
could be considered a serious bug for applications/Services that use a lot of unnamed teventobject.create calls.
As a temp work around this seemed to work:
var
guid:TGUID;
msg,name:string;
lasterr:nativeint;
begin
if CreateGUID(guid) = 0 then
name:=GUIDToString(guid) else name:='';
FDataAvailable := TEvent.Create(nil, True, False,name);
{$IFDEF MSWINDOWS}
lasterr:=GetLastError;
if (lasterr <> 0) then
begin
msg:=SysErrorMessage(lasterr);
raise Exception.Create(SCannotCreateEvent+':'+msg);
end;
{$ENDIF}
Mantis conversion info:
- Mantis ID: 30747
- OS: Windows
- OS Build: 7
- Platform: Windows
- Version: 3.0.0
- Fixed in version: 3.1.1
- Fixed in revision: 34736 (#f8b45810)