nsswitch/wb_common.c: fix socket fd and memory leaks of global state
authorStefan Metzmacher <metze@samba.org>
Thu, 7 Sep 2023 13:59:59 +0000 (15:59 +0200)
committerJule Anger <janger@samba.org>
Mon, 18 Sep 2023 16:55:30 +0000 (16:55 +0000)
commit374ba0d2c9a32ade701d7cdd25034692fe055108
treeaf73ec9ed184cc021a859d81fab7f7da459ab41c
parent7d04c32ed7eaacfa7e233a7cc141344041c20fc5
nsswitch/wb_common.c: fix socket fd and memory leaks of global state

When we are called in wb_atfork_child() or winbind_destructor(),
wb_thread_ctx_destructor() is not called for the global state
of the current nor any other thread, which means we would
leak the related memory and socket fds.

Now we maintain a global list protected by a global mutex.
We traverse the list and close all socket fds, which are no
longer used (winbind_destructor) or no longer valid in the
current process (wb_atfork_child), in addition we 'autofree'
the ones, which are only visible internally as global (per thread)
context.

BUG: https://bugzilla.samba.org/show_bug.cgi?id=15464

Tested-by: Krzysztof Piotr Oledzki <ole@ans.pl>
Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
Autobuild-User(master): Stefan Metzmacher <metze@samba.org>
Autobuild-Date(master): Thu Sep 14 18:53:07 UTC 2023 on atb-devel-224

(cherry picked from commit 4af3faace481d23869b64485b791bdd43d8972c5)

Autobuild-User(v4-19-test): Jule Anger <janger@samba.org>
Autobuild-Date(v4-19-test): Mon Sep 18 16:55:30 UTC 2023 on atb-devel-224
nsswitch/wb_common.c