Merge branch 'bugfix/malloc_warnings_event_loop' into 'master'

esp_event: fix possible malloc free issues found by static analyzer

See merge request idf/esp-idf!5142
This commit is contained in:
Angus Gratton 2019-06-13 10:10:26 +08:00
commit 9909206b16

View File

@ -212,7 +212,7 @@ static esp_err_t base_node_add_handler(esp_event_base_node_t* base_node, int32_t
id_node = (esp_event_id_node_t*) calloc(1, sizeof(*id_node)); id_node = (esp_event_id_node_t*) calloc(1, sizeof(*id_node));
if (!id_node) { if (!id_node) {
ESP_LOGI(TAG, "alloc for new id node failed"); ESP_LOGE(TAG, "alloc for new id node failed");
return ESP_ERR_NO_MEM; return ESP_ERR_NO_MEM;
} }
@ -229,6 +229,8 @@ static esp_err_t base_node_add_handler(esp_event_base_node_t* base_node, int32_t
else { else {
SLIST_INSERT_AFTER(last_id_node, id_node, next); SLIST_INSERT_AFTER(last_id_node, id_node, next);
} }
} else {
free(id_node);
} }
return err; return err;
@ -280,6 +282,8 @@ static esp_err_t loop_node_add_handler(esp_event_loop_node_t* loop_node, esp_eve
else { else {
SLIST_INSERT_AFTER(last_base_node, base_node, next); SLIST_INSERT_AFTER(last_base_node, base_node, next);
} }
} else {
free(base_node);
} }
return err; return err;
@ -414,7 +418,7 @@ esp_err_t esp_event_loop_create(const esp_event_loop_args_t* event_loop_args, es
loop = calloc(1, sizeof(*loop)); loop = calloc(1, sizeof(*loop));
if (loop == NULL) { if (loop == NULL) {
ESP_LOGE(TAG, "alloc for event loop failed"); ESP_LOGE(TAG, "alloc for event loop failed");
goto on_err; return err;
} }
loop->queue = xQueueCreate(event_loop_args->queue_size , sizeof(esp_event_post_instance_t)); loop->queue = xQueueCreate(event_loop_args->queue_size , sizeof(esp_event_post_instance_t));
@ -692,6 +696,8 @@ esp_err_t esp_event_handler_register_with(esp_event_loop_handle_t event_loop, es
else { else {
SLIST_INSERT_AFTER(last_loop_node, loop_node, next); SLIST_INSERT_AFTER(last_loop_node, loop_node, next);
} }
} else {
free(loop_node);
} }
} }
else { else {