Fix crash when switching serial ports #19
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Switching port after sending a message was crashing the program
How:
Open QModbus and select the RTU tab.
Make it active, select a valid port and hit send (If the first port was not valid you will need to toggle active checkbox).
The message should be sent and a response or timeout received.
Switch to another port (the program should crash).
Why:
Toggling active checkbox causes mainwindow to fetch modbus_t pointer from rtu widget.
If a valid port was selected then modbus_t should be valid.
Changing serial port settings frees modbus_t and allocates a new one.
mainwindow is not informed so modbus_poll() uses the freed one and causes a crash.
Fix:
When changing the serial port we now emit serialPortActive(true).
This causes mainwindow to update modbus_t thereby avoiding the crash.
This solution also means we do not need to toggle the active checkbox when we change the serial port.
Maybe related to #10