Server wrapper: server stopped state should be enforced when calling clear
The server wrapper does not check server has been stopped when calling clear operation which might lead service/SC layer to access freed memory.
Using the server wrapper there are 2 possibilities to manage server lifetime:
- using
SOPC_ServerHelper_StartServer
function to start the server, it is mandatory to callSOPC_ServerHelper_StopServer
before callingSOPC_ServerConfigHelper_Clear
function. - using
SOPC_ServerHelper_Serve
function the call is blocking until stop thusSOPC_ServerConfigHelper_Clear
can be called on Serve function return
Thus in case 1. it should be enforced that SOPC_ServerHelper_StopServer
was called prior to SOPC_ServerConfigHelper_Clear
.
In both cases the internal state shall be STOPPED or < SOPC_SERVER_STATE_STARTED for a Clear operation.
Moreover in both cases SOPC_HelperInternal_ActualShutdownServer
use asynchronous operation to close the EPs but does not actually wait for all EPs to be closed. This means the Clear operation might be called before the closed EP callback has been called for all EPs and thus memory issues are still possible (but unlikely).
Note: state shall be set to STOPPED if no EP is opened when SOPC_HelperInternal_ActualShutdownServer
is called, this is not done for now.
Note: the current behavior is correct regarding the StopServer API documentation but it seems it should be changed to avoid giving responsibility to user application to wait for a callback call:
If server started with ::SOPC_ServerHelper_StartServer, this call is blocking during shutdown phase and ::SOPC_ServerStopped_Fct is called on actual shutdown. Caller is responsible to wait for ::SOPC_ServerStopped_Fct call prior to use any ::SOPC_ServerConfigHelper_Clear function.