ed-chemnitz / qmodbus

GNU General Public License v2.0
279 stars 128 forks source link

Fix crash when switching serial ports #19

Closed shiftee closed 6 years ago

shiftee commented 6 years ago

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 https://github.com/ed-chemnitz/qmodbus/issues/10

tobydox commented 6 years ago

Thanks for your contribution! There seems to be a merge conflict. Can you fix this so I can merge your changes?

shiftee commented 6 years ago

Sorry, that should be fixed now