tuanpmt/ESP8266MQTTClient

Possible error in out_buffer free memory

Opened this issue · 0 comments

hdrut commented

Hi, I see in ESP8266MQTTClient.cpp the following memory allocations for in and out buffers:

_state.in_buffer = (uint8_t *)malloc(DEFAULT_MQTT_BUFFER_SIZE_BYTES);
if(_state.in_buffer == NULL) {
    LOG("Not enought memory\r\n");
    return false;
}
_state.in_buffer_length = DEFAULT_MQTT_BUFFER_SIZE_BYTES;
_state.out_buffer = (uint8_t *)malloc(DEFAULT_MQTT_BUFFER_SIZE_BYTES);
if(_state.in_buffer == NULL) {
    free(_state.in_buffer);
    LOG("Not enought memory\r\n");
    return false;
}

I believe the last check over in_buffer should be done over out_buffer, and also both mallocs() should be freed. Please correct me if i'm wrong...

Thanks, rgds,

Richard