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 17:25:43 +0000 (17:25 +0000)
commit82d6f8a6ce3918b51a9422101823328084a27ffa
tree6406091b928f9f77e7a75bd74c18758aee36e310
parent3d8e8ed15942374939c95384b5cd03b0162000ad
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-18-test): Jule Anger <janger@samba.org>
Autobuild-Date(v4-18-test): Mon Sep 18 17:25:43 UTC 2023 on atb-devel-224
nsswitch/wb_common.c