dawidchyrzynski / arduino-home-assistant

ArduinoHA allows to integrate an Arduino/ESP based device with Home Assistant using MQTT.
https://dawidchyrzynski.github.io/arduino-home-assistant/
GNU Affero General Public License v3.0
480 stars 116 forks source link

Bug in HASelect's destructor (memory leak) #169

Closed martaisty closed 1 year ago

martaisty commented 1 year ago

Hi @dawidchyrzynski , excellent library :+1: Could you please explain this destructor logic in HASelect? Isn't it a bug with a memory leak? https://github.com/dawidchyrzynski/arduino-home-assistant/blob/0fc32a5bad861ca76767ff13187f8afabcc4f9a0/src/device-types/HASelect.cpp#L25-L29

I suppose instead of this:

        if (optionsNb > 1) {
            for (uint8_t i = 0; i < optionsNb; i++) {
                delete options[i];
            }
        }

it should be

        for (uint8_t i = 0; i < optionsNb; i++) {
            delete[] options[i];
        }

Sorry, if this is a silly question, last time I worked with C++ was at university :smile:

martaisty commented 1 year ago

Sorry, never mind. I spotted this in setOptions https://github.com/dawidchyrzynski/arduino-home-assistant/blob/0fc32a5bad861ca76767ff13187f8afabcc4f9a0/src/device-types/HASelect.cpp#L49-L52 That's why.. Now I understand, closing the issue