There are 2 issues with the ctor of class CtrlRingBuffer
The input parameters are the pointers, but they are not checked for a nullptr, what brings the risk of unexpected crash
Parameter 'connector' must be removed
The reason of this is because connector can be used just when it is initialized, but the ctor takes always not initialized input parameter, see the code
auto width = stoi(resolution.substr(0, pos));
auto height = stoi(resolution.substr(++pos));
auto connector = mDisplay->createConnector(getDomId(), id, width, height);
CtrlRingBufferPtr ctrlRingBuffer(
new CtrlRingBuffer(mDisplay,
connector,
bufferStorage,
eventRingBuffer,
getDomId(), port, ref));
There is not any sense to create the not initialized connector from mDisplay, and put both parameters in the ctor of CtrlRingBuffer. This behavior just increase the risk of the exceptions (what can be avoided) and crashes(pointers are not checked for the nullptr), besides - all code to work with connector must be wrapped in try{}catch{} block or it is necessary to , because connector is not initialized to check the connector state.
Solution
Remove input parameter 'connector'
Add the pointers validation in ctor of CtrlRingBuffer
Create the conenctor just when it is necessary, in our case this is DisplayCommandHandler::setConfig(const xendispl_req& req,
xendispl_resp& rsp)
Because, CtrlRingBuffer has the member mCommandHandler,
Remove input parameter 'connector' from the ctor declaration of DisplayCommandHandler
Instead of if([connector->]isInitialilised) add if(connector) where required. (and totaly remove from connector implementaiton)
Description
There are 2 issues with the ctor of class CtrlRingBuffer
Solution