From 6c57a6cc3dab9317c0d8d27e5eea740be1467eb2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Sur=C3=BD?= Date: Mon, 10 May 2021 11:36:54 +0200 Subject: [PATCH] Add isc_taskmgr_detach when task is created while shutting down When taskmgr is shutting down, the creating the task would attach to the taskmgr, but don't detach on error condition. --- lib/isc/include/isc/task.h | 2 +- lib/isc/task.c | 11 ++++++++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/lib/isc/include/isc/task.h b/lib/isc/include/isc/task.h index 4883785a22..33f064ffc7 100644 --- a/lib/isc/include/isc/task.h +++ b/lib/isc/include/isc/task.h @@ -644,7 +644,7 @@ isc_task_privileged(isc_task_t *task); void isc_taskmgr_attach(isc_taskmgr_t *, isc_taskmgr_t **); void -isc_taskmgr_detach(isc_taskmgr_t *); +isc_taskmgr_detach(isc_taskmgr_t **); /*%< * Attach/detach the task manager. */ diff --git a/lib/isc/task.c b/lib/isc/task.c index 9849faeafc..abdcb56cdd 100644 --- a/lib/isc/task.c +++ b/lib/isc/task.c @@ -193,7 +193,7 @@ task_finished(isc_task_t *task) { task->magic = 0; isc_mem_put(mctx, task, sizeof(*task)); - isc_taskmgr_detach(manager); + isc_taskmgr_detach(&manager); } isc_result_t @@ -265,6 +265,7 @@ isc_task_create_bound(isc_taskmgr_t *manager, unsigned int quantum, if (exiting) { isc_mutex_destroy(&task->lock); + isc_taskmgr_detach(&task->manager); isc_mem_put(manager->mctx, task, sizeof(*task)); return (ISC_R_SHUTTINGDOWN); } @@ -959,8 +960,12 @@ isc_taskmgr_attach(isc_taskmgr_t *source, isc_taskmgr_t **targetp) { } void -isc_taskmgr_detach(isc_taskmgr_t *manager) { - REQUIRE(VALID_MANAGER(manager)); +isc_taskmgr_detach(isc_taskmgr_t **managerp) { + REQUIRE(managerp != NULL); + REQUIRE(VALID_MANAGER(*managerp)); + + isc_taskmgr_t *manager = *managerp; + *managerp = NULL; if (isc_refcount_decrement(&manager->references) == 1) { manager_free(manager);