From c8ee3d452520a0096a2fa36ca7465f65d7955330 Mon Sep 17 00:00:00 2001 From: Jule Anger Date: Wed, 1 Mar 2023 09:47:09 +0000 Subject: [PATCH] s4:process_prefork: avoid memory leaks caused by messaging_post_self Sending a message to a process with multiple tevent contexts can cause a message to get stuck and cause a data leak. In general it's safer to call imessaging_dgm_unref_ev() before talloc_free()... Pair-Programmed-With: Stefan Metzmacher Signed-off-by: Jule Anger Signed-off-by: Stefan Metzmacher Reviewed-by: Andrew Bartlett --- source4/samba/process_prefork.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/source4/samba/process_prefork.c b/source4/samba/process_prefork.c index 35145c7403d..a8dee820458 100644 --- a/source4/samba/process_prefork.c +++ b/source4/samba/process_prefork.c @@ -414,8 +414,19 @@ static void prefork_fork_master( pd.instances++; } + /* + * Make sure the messaging context + * used by the workers is no longer + * active on ev2, otherwise we + * would have memory leaks, because + * we queue incoming messages + * and never process them via ev2. + */ + imessaging_dgm_unref_ev(ev2); + /* Don't listen on the sockets we just gave to the children */ tevent_loop_wait(ev); + imessaging_dgm_unref_ev(ev); TALLOC_FREE(ev); /* We need to keep ev2 until we're finished for the messaging to work */ TALLOC_FREE(ev2); @@ -748,6 +759,7 @@ static void prefork_fork_worker(struct task_server *task, */ free(w); + imessaging_dgm_unref_ev(ev); TALLOC_FREE(ev); process_set_title("%s(%d)", @@ -773,6 +785,7 @@ static void prefork_fork_worker(struct task_server *task, TALLOC_FREE(ctx); } tevent_loop_wait(ev2); + imessaging_dgm_unref_ev(ev2); talloc_free(ev2); exit(0); } -- 2.11.4.GIT