Skip to content

fix(zigbee): memory leak issue with malloc #11196

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 11 commits into from
Closed
Prev Previous commit
Next Next commit
fix(zigbee): not using reserved word string
  • Loading branch information
SuGlider authored Mar 28, 2025
commit 558747d23b4e44295f3bf99546b7725f89731ddc
20 changes: 10 additions & 10 deletions libraries/Zigbee/src/ZigbeeEP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -246,22 +246,22 @@ void ZigbeeEP::zbReadBasicCluster(const esp_zb_zcl_attribute_t *attribute) {
/* Basic cluster attributes */
if (attribute->id == ESP_ZB_ZCL_ATTR_BASIC_MANUFACTURER_NAME_ID && attribute->data.type == ESP_ZB_ZCL_ATTR_TYPE_CHAR_STRING && attribute->data.value) {
zbstring_t *zbstr = (zbstring_t *)attribute->data.value;
std::vector<char> string(zbstr->len + 1);
memcpy(string.data(), zbstr->data, zbstr->len);
string[zbstr->len] = '\0';
log_i("Peer Manufacturer is \"%s\"", string);
std::vector<char> m_manufacturer(zbstr->len + 1);
memcpy(m_manufacturer.data(), zbstr->data, zbstr->len);
m_manufacturer[zbstr->len] = '\0';
log_i("Peer Manufacturer is \"%s\"", m_manufacturer);
free(_read_manufacturer); // Free any previously allocated memory
_read_manufacturer = strdup(string.data()); // Duplicate the string for persistent storage
_read_manufacturer = strdup(m_manufacturer.data()); // Duplicate the information for persistent storage
xSemaphoreGive(lock);
}
if (attribute->id == ESP_ZB_ZCL_ATTR_BASIC_MODEL_IDENTIFIER_ID && attribute->data.type == ESP_ZB_ZCL_ATTR_TYPE_CHAR_STRING && attribute->data.value) {
zbstring_t *zbstr = (zbstring_t *)attribute->data.value;
std::vector<char> string(zbstr->len + 1);
memcpy(string.data(), zbstr->data, zbstr->len);
string[zbstr->len] = '\0';
log_i("Peer Model is \"%s\"", string);
std::vector<char> m_model(zbstr->len + 1);
memcpy(m_model.data(), zbstr->data, zbstr->len);
m_model[zbstr->len] = '\0';
log_i("Peer Model is \"%s\"", m_model);
free(_read_model); // Free any previously allocated memory
_read_model = strdup(string.data()); // Duplicate the string for persistent storage
_read_model = strdup(m_model.data()); // Duplicate the information for persistent storage
xSemaphoreGive(lock);
}
}
Expand Down
Loading