mirror of
https://github.com/espressif/esp-idf.git
synced 2026-10-02 03:00:34 +03:00
fix(esp_event): free queued legacy cleanup ctx on loop delete
When a loop is deleted while an internal legacy "cleanup" event is still queued (posted by a deferred self-unregistration from within a handler), esp_event_loop_delete() drained the queue but only freed the post payload, leaking the heap copy of the handler context allocated for the legacy path. Free ctx->handler_ctx for queued legacy cleanup events while draining the queue, mirroring the cleanup done in esp_event_loop_run(). Add a regression test that leaves a legacy cleanup event queued and asserts no memory is leaked on loop deletion.
This commit is contained in:
@@ -830,6 +830,12 @@ esp_err_t esp_event_loop_delete(esp_event_loop_handle_t event_loop)
|
||||
// Drop existing posts on the queue
|
||||
esp_event_post_instance_t post;
|
||||
while (xQueueReceive(loop->queue, &post, 0) == pdTRUE) {
|
||||
if (post.base == esp_event_handler_cleanup) {
|
||||
esp_event_remove_handler_context_t* ctx = (esp_event_remove_handler_context_t*)post.data.ptr;
|
||||
if (ctx->legacy) {
|
||||
free(ctx->handler_ctx);
|
||||
}
|
||||
}
|
||||
post_instance_delete(&post);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user