use string as a pointer to keep the reference to id

This commit is contained in:
Nicu Hodos 2024-10-05 21:29:52 +02:00
parent e246158502
commit 996683d43c

View File

@ -62,10 +62,7 @@ struct PollinSwitch : Switch {
PollinSwitch(const char* group, const unsigned char channel, const char* name = nullptr, const char* area = nullptr)
: Switch(nullptr, [group, channel]{
// copy id from string into a new pointer, to avoid memory leaks
string s = Protocol_1::buildId(group, channel);
char* uId = new char[s.length() + 1];
strcpy(uId, s.c_str());
return uId;
return (new string{Protocol_1::buildId(group, channel)})->c_str();
}()), group(group), channel(channel) {
if (!name) name = (new string{string(man).append(" ").append(id)})->c_str();
mainDevice = &DeviceConfig::create(id).withName(name).withManufacturer(man).withArea(area).withParent(gatewayDevice);