Chasing memory corruption (2)
Due further addItem() calls the inner rItems vector reallocated and
pointer to colorMode was dangling.
TODO we need saner conventions to prevent such issues.
Tracked down with clang address sanitizer.
QMAKE_CXXFLAGS_DEBUG += -fsanitize=address -fno-omit-frame-pointer
QMAKE_LFLAGS_DEBUG += -fsanitize=address
@@ -481,9 +481,7 @@ void LightNode::setHaEndpoint(const deCONZ::SimpleDescriptor &endpoint)
}
else if (i->id() == COLOR_CLUSTER_ID)
{
- ResourceItem *colorMode = addItem(DataTypeString, RStateColorMode);
-
- colorMode->setValue(QVariant("hs"));
+ addItem(DataTypeString, RStateColorMode)->setValue(QVariant("hs"));
switch (haEndpoint().deviceId())
{
@@ -500,7 +498,7 @@ void LightNode::setHaEndpoint(const deCONZ::SimpleDescriptor &endpoint)
if (haEndpoint().deviceId() == DEV_ID_Z30_COLOR_TEMPERATURE_LIGHT ||
haEndpoint().deviceId() == DEV_ID_ZLL_COLOR_TEMPERATURE_LIGHT)
{
- colorMode->setValue(QVariant("ct"));
+ item(RStateColorMode)->setValue(QVariant("ct")); // note due addItem() calls, pointer is different here
}
}
[[clang::fallthrough]];
