thread-freeres.c 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. /* Free resources stored in thread-local variables on thread exit.
  2. Copyright (C) 2003-2026 Free Software Foundation, Inc.
  3. This file is part of the GNU C Library.
  4. The GNU C Library is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU Lesser General Public
  6. License as published by the Free Software Foundation; either
  7. version 2.1 of the License, or (at your option) any later version.
  8. The GNU C Library is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. Lesser General Public License for more details.
  12. You should have received a copy of the GNU Lesser General Public
  13. License along with the GNU C Library; if not, see
  14. <https://www.gnu.org/licenses/>. */
  15. #include <libc-internal.h>
  16. #include <malloc-internal.h>
  17. #include <set-freeres.h>
  18. #include <shlib-compat.h>
  19. #include <tls-internal.h>
  20. /* Thread shutdown function. Note that this function must be called
  21. for threads during shutdown for correctness reasons. Unlike
  22. __libc_freeres, skipping calls to it is not a valid optimization.
  23. This is called directly from pthread_create as the thread exits. */
  24. void
  25. __libc_thread_freeres (void)
  26. {
  27. #if SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_32)
  28. __rpc_thread_destroy ();
  29. #endif
  30. call_function_static_weak (__res_thread_freeres);
  31. call_function_static_weak (__glibc_tls_internal_free);
  32. call_function_static_weak (__libc_dlerror_result_free);
  33. /* This should come last because it shuts down malloc for this
  34. thread and the other shutdown functions might well call free. */
  35. call_function_static_weak (__malloc_arena_thread_freeres);
  36. }