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)
committerStefan Metzmacher <metze@samba.org>
Thu, 14 Sep 2023 18:53:07 +0000 (18:53 +0000)
commit4af3faace481d23869b64485b791bdd43d8972c5
tree5226db0547f2ba7955555a678451bdec4e1460df
parent91b30a7261e6455d3a4f31728c23e4849e3945b9
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
nsswitch/wb_common.c