hwmontemp: Fix NULL pointer dereference
When createSensors() is called with activateOnly set to false
and a sensor does not have a hwmonFile it is added as nullptr
to sensors array.
This causes interfaceRemoved() to crash as it dereferences
that sensor without first checking if it's null.
Tested: hwmontempsensor no longer crashes when some random
interface is removed.
Change-Id: I8f63f753cca7341be5a0683e7b446f63ae92f8cb
Signed-off-by: Patrick Rudolph <patrick.rudolph@9elements.com>
diff --git a/src/HwmonTempMain.cpp b/src/HwmonTempMain.cpp
index 8d41fab..a85d13a 100644
--- a/src/HwmonTempMain.cpp
+++ b/src/HwmonTempMain.cpp
@@ -538,7 +538,7 @@
auto sensorIt = sensors.begin();
while (sensorIt != sensors.end())
{
- if ((sensorIt->second->configurationPath == path) &&
+ if (sensorIt->second && (sensorIt->second->configurationPath == path) &&
(std::find(interfaces.begin(), interfaces.end(),
sensorIt->second->configInterface) != interfaces.end()))
{