@@ -350,21 +350,13 @@ static esp_err_t free_default_value(attribute_t *attribute)
350
350
/* Free value if data is more than 2 bytes or if it is min max attribute */
351
351
if (current_attribute->flags & ATTRIBUTE_FLAG_MIN_MAX) {
352
352
if (current_attribute->default_value_size > 2 ) {
353
- if (current_attribute->default_value .ptrToMinMaxValue ->defaultValue .ptrToDefaultValue ) {
354
- esp_matter_mem_free ((void *)current_attribute->default_value .ptrToMinMaxValue ->defaultValue .ptrToDefaultValue );
355
- }
356
- if (current_attribute->default_value .ptrToMinMaxValue ->minValue .ptrToDefaultValue ) {
357
- esp_matter_mem_free ((void *)current_attribute->default_value .ptrToMinMaxValue ->minValue .ptrToDefaultValue );
358
- }
359
- if (current_attribute->default_value .ptrToMinMaxValue ->maxValue .ptrToDefaultValue ) {
360
- esp_matter_mem_free ((void *)current_attribute->default_value .ptrToMinMaxValue ->maxValue .ptrToDefaultValue );
361
- }
353
+ esp_matter_mem_free ((void *)current_attribute->default_value .ptrToMinMaxValue ->defaultValue .ptrToDefaultValue );
354
+ esp_matter_mem_free ((void *)current_attribute->default_value .ptrToMinMaxValue ->minValue .ptrToDefaultValue );
355
+ esp_matter_mem_free ((void *)current_attribute->default_value .ptrToMinMaxValue ->maxValue .ptrToDefaultValue );
362
356
}
363
357
esp_matter_mem_free ((void *)current_attribute->default_value .ptrToMinMaxValue );
364
358
} else if (current_attribute->default_value_size > 2 ) {
365
- if (current_attribute->default_value .ptrToDefaultValue ) {
366
- esp_matter_mem_free ((void *)current_attribute->default_value .ptrToDefaultValue );
367
- }
359
+ esp_matter_mem_free ((void *)current_attribute->default_value .ptrToDefaultValue );
368
360
}
369
361
return ESP_OK;
370
362
}
@@ -493,30 +485,20 @@ static esp_err_t disable(endpoint_t *endpoint)
493
485
/* Free attributes */
494
486
esp_matter_mem_free ((void *)endpoint_type->cluster [cluster_index].attributes );
495
487
/* Free commands */
496
- if (endpoint_type->cluster [cluster_index].acceptedCommandList ) {
497
- esp_matter_mem_free ((void *)endpoint_type->cluster [cluster_index].acceptedCommandList );
498
- }
499
- if (endpoint_type->cluster [cluster_index].generatedCommandList ) {
500
- esp_matter_mem_free ((void *)endpoint_type->cluster [cluster_index].generatedCommandList );
501
- }
488
+ esp_matter_mem_free ((void *)endpoint_type->cluster [cluster_index].acceptedCommandList );
489
+ esp_matter_mem_free ((void *)endpoint_type->cluster [cluster_index].generatedCommandList );
502
490
/* Free events */
503
- if (endpoint_type->cluster [cluster_index].eventList ) {
504
- esp_matter_mem_free ((void *)endpoint_type->cluster [cluster_index].eventList );
505
- }
491
+ esp_matter_mem_free ((void *)endpoint_type->cluster [cluster_index].eventList );
506
492
}
507
493
esp_matter_mem_free ((void *)endpoint_type->cluster );
508
494
509
495
/* Free data versions */
510
- if (current_endpoint->data_versions_ptr ) {
511
- esp_matter_mem_free (current_endpoint->data_versions_ptr );
512
- current_endpoint->data_versions_ptr = NULL ;
513
- }
496
+ esp_matter_mem_free (current_endpoint->data_versions_ptr );
497
+ current_endpoint->data_versions_ptr = NULL ;
514
498
515
499
/* Free device types */
516
- if (current_endpoint->device_types_ptr ) {
517
- esp_matter_mem_free (current_endpoint->device_types_ptr );
518
- current_endpoint->device_types_ptr = NULL ;
519
- }
500
+ esp_matter_mem_free (current_endpoint->device_types_ptr );
501
+ current_endpoint->device_types_ptr = NULL ;
520
502
521
503
/* Delete identify */
522
504
if (current_endpoint->identify ) {
@@ -572,9 +554,7 @@ esp_err_t enable(endpoint_t *endpoint)
572
554
DataVersion *data_versions_ptr = (DataVersion *)esp_matter_mem_calloc (1 , cluster_count * sizeof (DataVersion));
573
555
if (!data_versions_ptr) {
574
556
ESP_LOGE (TAG, " Couldn't allocate data_versions" );
575
- esp_matter_mem_free (data_versions_ptr);
576
557
esp_matter_mem_free (endpoint_type);
577
- current_endpoint->data_versions_ptr = NULL ;
578
558
current_endpoint->endpoint_type = NULL ;
579
559
/* goto cleanup is not used here to avoid 'crosses initialization' of data_versions below */
580
560
return ESP_ERR_NO_MEM;
@@ -777,50 +757,28 @@ esp_err_t enable(endpoint_t *endpoint)
777
757
return err;
778
758
779
759
cleanup:
780
- if (generated_command_ids) {
781
- esp_matter_mem_free (generated_command_ids);
782
- }
783
- if (accepted_command_ids) {
784
- esp_matter_mem_free (accepted_command_ids);
785
- }
786
- if (event_ids) {
787
- esp_matter_mem_free (event_ids);
788
- }
789
- if (matter_attributes) {
790
- esp_matter_mem_free (matter_attributes);
791
- }
760
+ esp_matter_mem_free (generated_command_ids);
761
+ esp_matter_mem_free (accepted_command_ids);
762
+ esp_matter_mem_free (event_ids);
763
+ esp_matter_mem_free (matter_attributes);
792
764
if (matter_clusters) {
793
765
for (int cluster_index = 0 ; cluster_index < cluster_count; cluster_index++) {
794
766
/* Free attributes */
795
- if (matter_clusters[cluster_index].attributes ) {
796
- esp_matter_mem_free ((void *)matter_clusters[cluster_index].attributes );
797
- }
767
+ esp_matter_mem_free ((void *)matter_clusters[cluster_index].attributes );
798
768
/* Free commands */
799
- if (matter_clusters[cluster_index].acceptedCommandList ) {
800
- esp_matter_mem_free ((void *)matter_clusters[cluster_index].acceptedCommandList );
801
- }
802
- if (matter_clusters[cluster_index].generatedCommandList ) {
803
- esp_matter_mem_free ((void *)matter_clusters[cluster_index].generatedCommandList );
804
- }
769
+ esp_matter_mem_free ((void *)matter_clusters[cluster_index].acceptedCommandList );
770
+ esp_matter_mem_free ((void *)matter_clusters[cluster_index].generatedCommandList );
805
771
/* Free events */
806
- if (matter_clusters[cluster_index].eventList ) {
807
- esp_matter_mem_free ((void *)matter_clusters[cluster_index].eventList );
808
- }
772
+ esp_matter_mem_free ((void *)matter_clusters[cluster_index].eventList );
809
773
}
810
774
esp_matter_mem_free (matter_clusters);
811
775
}
812
- if (data_versions_ptr) {
813
- esp_matter_mem_free (data_versions_ptr);
814
- current_endpoint->data_versions_ptr = NULL ;
815
- }
816
- if (device_types_ptr) {
817
- esp_matter_mem_free (device_types_ptr);
818
- current_endpoint->device_types_ptr = NULL ;
819
- }
820
- if (endpoint_type) {
821
- esp_matter_mem_free (endpoint_type);
822
- current_endpoint->endpoint_type = NULL ;
823
- }
776
+ esp_matter_mem_free (data_versions_ptr);
777
+ current_endpoint->data_versions_ptr = NULL ;
778
+ esp_matter_mem_free (device_types_ptr);
779
+ current_endpoint->device_types_ptr = NULL ;
780
+ esp_matter_mem_free (endpoint_type);
781
+ current_endpoint->endpoint_type = NULL ;
824
782
return err;
825
783
}
826
784
@@ -1178,15 +1136,11 @@ static esp_err_t destroy(attribute_t *attribute)
1178
1136
current_attribute->val .type == ESP_MATTER_VAL_TYPE_LONG_OCTET_STRING ||
1179
1137
current_attribute->val .type == ESP_MATTER_VAL_TYPE_ARRAY) {
1180
1138
/* Free buf */
1181
- if (current_attribute->val .val .a .b ) {
1182
- esp_matter_mem_free (current_attribute->val .val .a .b );
1183
- }
1139
+ esp_matter_mem_free (current_attribute->val .val .a .b );
1184
1140
}
1185
1141
1186
1142
/* Free bounds */
1187
- if (current_attribute->bounds ) {
1188
- esp_matter_mem_free (current_attribute->bounds );
1189
- }
1143
+ esp_matter_mem_free (current_attribute->bounds );
1190
1144
1191
1145
/* Erase the persistent data */
1192
1146
if (current_attribute->flags & ATTRIBUTE_FLAG_NONVOLATILE) {
@@ -1273,10 +1227,8 @@ esp_err_t set_val(attribute_t *attribute, esp_matter_attr_val_t *val)
1273
1227
val->type == ESP_MATTER_VAL_TYPE_LONG_CHAR_STRING || val->type == ESP_MATTER_VAL_TYPE_LONG_OCTET_STRING ||
1274
1228
val->type == ESP_MATTER_VAL_TYPE_ARRAY) {
1275
1229
/* Free old buf */
1276
- if (current_attribute->val .val .a .b ) {
1277
- esp_matter_mem_free (current_attribute->val .val .a .b );
1278
- current_attribute->val .val .a .b = NULL ;
1279
- }
1230
+ esp_matter_mem_free (current_attribute->val .val .a .b );
1231
+ current_attribute->val .val .a .b = NULL ;
1280
1232
if (val->val .a .s > 0 ) {
1281
1233
/* Alloc new buf */
1282
1234
uint8_t *new_buf = (uint8_t *)esp_matter_mem_calloc (1 , val->val .a .s );
0 commit comments