From 5083126ca7e706c10a67f4ffa739d5f6eb6474b6 Mon Sep 17 00:00:00 2001 From: Sebastian Reimers Date: Fri, 24 Feb 2023 20:41:43 +0100 Subject: [PATCH] async: fix cancel memory leaks --- src/async/async.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/async/async.c b/src/async/async.c index c0d1a3df3..c634078ba 100644 --- a/src/async/async.c +++ b/src/async/async.c @@ -270,10 +270,12 @@ void re_async_cancel(struct re_async *async, intptr_t id) mtx_lock(&async->mtx); - LIST_FOREACH(&async->workl, le) - { + le = list_head(&async->workl); + while (le) { struct async_work *w = le->data; + le = le->next; + if (w->id != id) continue; @@ -283,16 +285,19 @@ void re_async_cancel(struct re_async *async, intptr_t id) list_move(&w->le, &async->freel); } - LIST_FOREACH(&async->curl, le) - { + le = list_head(&async->curl); + while (le) { struct async_work *w = le->data; + le = le->next; + if (w->id != id) continue; w->workh = NULL; w->cb = NULL; w->arg = mem_deref(w->arg); + list_move(&w->le, &async->freel); } mtx_unlock(&async->mtx);