You are not logged in.
Hello,
I have run in Delphi 10.3 update 3 the project ..\SQLite3\Samples\ThirdPartyDemos\George\REST-tester\mORMotRESTsrv.dpr and an exception is raised when I set the port 80 and click on the "Start server" Button.
I have seen the problem and is the following :
In RestServerUnit.pas this code is executed :
fHTTPServer := TSQLHttpServer.Create(AnsiString(fServerSettings.Port), [fRestServer], '+', useBidirSocket);
After this, in SynCrtSock.pas, the fSock is created in the THttpServer constructor :
constructor THttpServer.Create
begin
.....
fSock := TCrtSocket.Bind(aPort); // BIND + LISTEN
....
end;
But the line fSock := TCrtSocket.Bind(aPort) raises in the TCrtSocket.OpenBind this exception :
raise ECrtSocket.CreateFmt('OpenBind(%s:%s,%s) failed: %s', [aServer,fPort,BINDTXT[doBind],BINDMSG[doBind]],-1);
So, when the destructor of the THttpServer occurs, an access violation is raised because fSock has a nil value, concretly here :
destructor THttpServer.Destroy;
begin
....
if not fExecuteFinished then begin
Sock.Close; // shutdown the socket to unlock Accept() in Execute
DirectShutdown(CallServer('127.0.0.1',Sock.Port,false,cslTCP,1)); // <--------------- WANING, Sock could be nil
end;
.............
end;
I have applied a correction to this code :
destructor THttpServer.Destroy;
begin
....
if not fExecuteFinished then begin
Sock.Close; // shutdown the socket to unlock Accept() in Execute
if Sock <> nil then // <--------------- avoid to use Sock when it is nil
DirectShutdown(CallServer('127.0.0.1',Sock.Port,false,cslTCP,1));
end;
.............
end;
Thank you.
Last edited by macc2010 (2020-02-14 00:28:40)
Offline
Please check https://synopse.info/fossil/info/4cf75d28b734d6c9
Thanks for the feedback!
Offline
Thank you very much.
Offline