Client Websocket disconnect issue
## Summary When disconnecting a TCustomWebsocketClient with a OnDisconnected event assigned application crash because FConnection was FreeAndNil before. ## System Information <!-- The more information are provided the easier it is to replicate the bug --> - **Operating system:** Windows 11 - **Processor architecture:** x86-64 - **Compiler version:** 3.2.2 (With fcl-web and fcl-net from main branch) - **Device:** Computer ## Steps to reproduce 1. Create a TWebsocketClient 2. Assign a disconnection event 3. Connect to a websocket server 4. Invoke disconnect from client ## Example Project <!-- If possible, please create an example project that exhibits the problematic behavior, and link to it here in the bug report. --> ## What is the current bug behavior? Application crashes with access violation at [fpwebsocketclient.pp:464](https://gitlab.com/freepascal.org/fpc/source/-/blob/main/packages/fcl-web/src/websocket/fpwebsocketclient.pp#L464) ## What is the expected (correct) behavior? Disconnection of TWebsocketClient with OnDisconnect triggering ## Relevant logs and/or screenshots Example code: ``` FClient:=TWebsocketClient.Create(Self); FClient.OnDisconnect:=@DoDisconnect; [.. setting uri and connect...] FClient.Disconnect(false); ``` Just before crash: ![Capture_d_écran_2022-06-15_005354](/uploads/3b061a917b4ca741bb20f5424b71be87/Capture_d_écran_2022-06-15_005354.png) ## Possible fixes I've replace `OnDisconnect(FConnection);` with `OnDisconnect(nil);`
issue