@@ -19,8 +19,8 @@ ZigbeeEP::ZigbeeEP(uint8_t endpoint) {
19
19
_ep_config.endpoint = 0 ;
20
20
_cluster_list = nullptr ;
21
21
_on_identify = nullptr ;
22
- _read_model[ 0 ] = ' \0 ' ;
23
- _read_manufacturer[ 0 ] = ' \0 ' ;
22
+ _read_model = NULL ;
23
+ _read_manufacturer = NULL ;
24
24
_time_status = 0 ;
25
25
if (!lock) {
26
26
lock = xSemaphoreCreateBinary ();
@@ -168,8 +168,11 @@ char *ZigbeeEP::readManufacturer(uint8_t endpoint, uint16_t short_addr, esp_zb_i
168
168
read_req.attr_number = ZB_ARRAY_LENTH (attributes);
169
169
read_req.attr_field = attributes;
170
170
171
- _read_manufacturer[0 ] = ' \0 ' ;
172
-
171
+ if (_read_manufacturer != NULL ) {
172
+ free (_read_manufacturer);
173
+ }
174
+ _read_manufacturer = NULL ;
175
+
173
176
esp_zb_lock_acquire (portMAX_DELAY);
174
177
esp_zb_zcl_read_attr_cmd_req (&read_req);
175
178
esp_zb_lock_release ();
@@ -203,7 +206,10 @@ char *ZigbeeEP::readModel(uint8_t endpoint, uint16_t short_addr, esp_zb_ieee_add
203
206
read_req.attr_number = ZB_ARRAY_LENTH (attributes);
204
207
read_req.attr_field = attributes;
205
208
206
- _read_model[0 ] = ' \0 ' ;
209
+ if (_read_model != NULL ) {
210
+ free (_read_model);
211
+ }
212
+ _read_model = NULL ;
207
213
208
214
esp_zb_lock_acquire (portMAX_DELAY);
209
215
esp_zb_zcl_read_attr_cmd_req (&read_req);
@@ -244,13 +250,15 @@ void ZigbeeEP::zbReadBasicCluster(const esp_zb_zcl_attribute_t *attribute) {
244
250
/* Basic cluster attributes */
245
251
if (attribute->id == ESP_ZB_ZCL_ATTR_BASIC_MANUFACTURER_NAME_ID && attribute->data .type == ESP_ZB_ZCL_ATTR_TYPE_CHAR_STRING && attribute->data .value ) {
246
252
zbstring_t *zbstr = (zbstring_t *)attribute->data .value ;
253
+ char *_read_manufacturer = (char *) malloc (zbstr->len + 1 );
247
254
memcpy (_read_manufacturer, zbstr->data , zbstr->len );
248
255
_read_manufacturer[zbstr->len ] = ' \0 ' ;
249
256
log_i (" Peer Manufacturer is \" %s\" " , _read_manufacturer);
250
257
xSemaphoreGive (lock);
251
258
}
252
259
if (attribute->id == ESP_ZB_ZCL_ATTR_BASIC_MODEL_IDENTIFIER_ID && attribute->data .type == ESP_ZB_ZCL_ATTR_TYPE_CHAR_STRING && attribute->data .value ) {
253
260
zbstring_t *zbstr = (zbstring_t *)attribute->data .value ;
261
+ char *_read_model = (char *) malloc (zbstr->len + 1 );
254
262
memcpy (_read_model, zbstr->data , zbstr->len );
255
263
_read_model[zbstr->len ] = ' \0 ' ;
256
264
log_i (" Peer Model is \" %s\" " , _read_model);
0 commit comments