diff mbox series

[v2] __cxa_thread_atexit_impl: Abort on allocation failure [BZ #18524]

Message ID 20210728072854.3915796-1-siddhesh@sourceware.org
State New
Headers show
Series [v2] __cxa_thread_atexit_impl: Abort on allocation failure [BZ #18524] | expand

Commit Message

Siddhesh Poyarekar July 28, 2021, 7:28 a.m. UTC
Abort in the unlikely event that allocation fails when trying to
register a TLS destructor.
---
 stdlib/cxa_thread_atexit_impl.c | 3 +++
 1 file changed, 3 insertions(+)

Comments

Florian Weimer July 28, 2021, 7:31 a.m. UTC | #1
* Siddhesh Poyarekar:

> @@ -104,6 +105,8 @@ __cxa_thread_atexit_impl (dtor_func func, void *obj, void *dso_symbol)
>  
>    /* Prepend.  */
>    struct dtor_list *new = calloc (1, sizeof (struct dtor_list));
> +  if (__glibc_unlikely (new == NULL))
> +    __libc_fatal ("failed to register TLS destructor: out of memory");
>    new->func = func;
>    new->obj = obj;
>    new->next = tls_dtor_list;

Please add "Fatal glibc error: " and "\n".

Thanks,
Florian
diff mbox series

Patch

diff --git a/stdlib/cxa_thread_atexit_impl.c b/stdlib/cxa_thread_atexit_impl.c
index 577ed30931..d789f043f2 100644
--- a/stdlib/cxa_thread_atexit_impl.c
+++ b/stdlib/cxa_thread_atexit_impl.c
@@ -72,6 +72,7 @@ 
    is not very different from a case where __call_tls_dtors is called after
    _dl_close_worker on the DSO and hence is an accepted execution.  */
 
+#include <stdio.h>
 #include <stdlib.h>
 #include <ldsodefs.h>
 
@@ -104,6 +105,8 @@  __cxa_thread_atexit_impl (dtor_func func, void *obj, void *dso_symbol)
 
   /* Prepend.  */
   struct dtor_list *new = calloc (1, sizeof (struct dtor_list));
+  if (__glibc_unlikely (new == NULL))
+    __libc_fatal ("failed to register TLS destructor: out of memory");
   new->func = func;
   new->obj = obj;
   new->next = tls_dtor_list;