From 53c975943952439db8097073cae66dc6278c3ec4 Mon Sep 17 00:00:00 2001 From: nymea Date: Sat, 21 Sep 2019 09:01:13 +0200 Subject: [PATCH] added pointer checks --- ws2812fx/devicepluginws2812fx.cpp | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/ws2812fx/devicepluginws2812fx.cpp b/ws2812fx/devicepluginws2812fx.cpp index e40fd5c1..db00c6a1 100644 --- a/ws2812fx/devicepluginws2812fx.cpp +++ b/ws2812fx/devicepluginws2812fx.cpp @@ -305,9 +305,11 @@ void DevicePluginWs2812fx::deviceRemoved(Device *device) m_usedInterfaces.removeAll(device->paramValue(ws2812fxDeviceSerialPortParamTypeId).toString()); QSerialPort *serialPort = m_serialPorts.take(device); - serialPort->flush(); - serialPort->close(); - serialPort->deleteLater(); + if(serialPort) { + serialPort->flush(); + serialPort->close(); + serialPort->deleteLater(); + } } if (myDevices().empty()) { @@ -320,6 +322,8 @@ void DevicePluginWs2812fx::onReadyRead() { QSerialPort *serialPort = static_cast(sender()); Device *device = m_serialPorts.key(serialPort); + if (!device) + return; QByteArray data; while (serialPort->canReadLine()) { @@ -402,6 +406,8 @@ void DevicePluginWs2812fx::onSerialError(QSerialPort::SerialPortError error) { QSerialPort *serialPort = static_cast(sender()); Device *device = m_serialPorts.key(serialPort); + if (!device) + return; if (error != QSerialPort::NoError && serialPort->isOpen()) { qCCritical(dcWs2812fx()) << "Serial port error:" << error << serialPort->errorString();