From ca43af97d219f2de836a50ecaf24532445a3da66 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Fri, 9 Sep 2016 13:28:51 +0200 Subject: [PATCH] pthreadpool_tevent: Drop running jobs on talloc_free Enable us to destroy a pthreadpool_tevent structure with active jobs Signed-off-by: Volker Lendecke Reviewed-by: Jeremy Allison --- source3/lib/pthreadpool/pthreadpool_tevent.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/source3/lib/pthreadpool/pthreadpool_tevent.c b/source3/lib/pthreadpool/pthreadpool_tevent.c index e4efc2d8e0c..253a8673518 100644 --- a/source3/lib/pthreadpool/pthreadpool_tevent.c +++ b/source3/lib/pthreadpool/pthreadpool_tevent.c @@ -76,6 +76,7 @@ int pthreadpool_tevent_init(TALLOC_CTX *mem_ctx, unsigned max_threads, static int pthreadpool_tevent_destructor(struct pthreadpool_tevent *pool) { + struct pthreadpool_tevent_job_state *state, *next; int ret; ret = pthreadpool_destroy(pool->pool); @@ -84,8 +85,10 @@ static int pthreadpool_tevent_destructor(struct pthreadpool_tevent *pool) } pool->pool = NULL; - if (pool->jobs != NULL) { - abort(); + for (state = pool->jobs; state != NULL; state = next) { + next = state->next; + DLIST_REMOVE(pool->jobs, state); + state->pool = NULL; } return 0; @@ -114,7 +117,7 @@ static int pthreadpool_tevent_job_state_destructor( /* * We need to reparent to a long term context. */ - (void)talloc_reparent(state->req, state->pool, state); + (void)talloc_reparent(state->req, NULL, state); state->req = NULL; return -1; } @@ -214,8 +217,10 @@ static void pthreadpool_tevent_job_done(struct tevent_context *ctx, struct pthreadpool_tevent_job_state *state = talloc_get_type_abort( private_data, struct pthreadpool_tevent_job_state); - DLIST_REMOVE(state->pool->jobs, state); - state->pool = NULL; + if (state->pool != NULL) { + DLIST_REMOVE(state->pool->jobs, state); + state->pool = NULL; + } TALLOC_FREE(state->tctx); -- 2.11.4.GIT