#1 2020-02-14 00:18:59

macc2010
Member
Registered: 2015-12-28
Posts: 8

EAccessViolation at SynCrtSock.THttpServer.Destroy (6254)

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

#2 2020-02-15 11:21:24

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,673
Website

Re: EAccessViolation at SynCrtSock.THttpServer.Destroy (6254)

Please check https://synopse.info/fossil/info/4cf75d28b734d6c9

Thanks for the feedback!

Offline

#3 2020-02-15 22:03:38

macc2010
Member
Registered: 2015-12-28
Posts: 8

Re: EAccessViolation at SynCrtSock.THttpServer.Destroy (6254)

Thank you very much.

Offline

Board footer

Powered by FluxBB