diff mbox series

[15/19] nptl: Destroy the default thread attribute as part of freeres

Message ID d031b6731b55a60ae678eca3e12a3f4dc8074ede.1589884403.git.fweimer@redhat.com
State New
Headers show
Series Signal mask for timer helper thread | expand

Commit Message

Florian Weimer May 19, 2020, 10:44 a.m. UTC
This avoids a spurious memory leak report by valgrind.
---
 nptl/nptlfreeres.c                |  1 +
 nptl/pthreadP.h                   |  2 ++
 nptl/pthread_setattr_default_np.c | 10 ++++++++++
 3 files changed, 13 insertions(+)

Comments

Carlos O'Donell June 2, 2020, 3:41 a.m. UTC | #1
On 5/19/20 6:44 AM, Florian Weimer via Libc-alpha wrote:
> This avoids a spurious memory leak report by valgrind.

OK for master.

Reviewed-by: Carlos O'Donell <carlos@redhat.com>

> ---
>  nptl/nptlfreeres.c                |  1 +
>  nptl/pthreadP.h                   |  2 ++
>  nptl/pthread_setattr_default_np.c | 10 ++++++++++
>  3 files changed, 13 insertions(+)
> 
> diff --git a/nptl/nptlfreeres.c b/nptl/nptlfreeres.c
> index dda11e5922..07aa34adfa 100644
> --- a/nptl/nptlfreeres.c
> +++ b/nptl/nptlfreeres.c
> @@ -25,6 +25,7 @@
>  void
>  __libpthread_freeres (void)
>  {
> +  call_function_static_weak (__default_pthread_attr_freeres);

OK.

>    call_function_static_weak (__nptl_stacks_freeres);
>    call_function_static_weak (__shm_directory_freeres);
>    call_function_static_weak (__nptl_unwind_freeres);
> diff --git a/nptl/pthreadP.h b/nptl/pthreadP.h
> index acc8e88e4a..ed30b72923 100644
> --- a/nptl/pthreadP.h
> +++ b/nptl/pthreadP.h
> @@ -201,6 +201,8 @@ enum
>  /* Default pthread attributes.  */
>  extern union pthread_attr_transparent __default_pthread_attr attribute_hidden;
>  extern int __default_pthread_attr_lock attribute_hidden;
> +/* Called from __libpthread_freeres to deallocate the default attribute.  */
> +extern void __default_pthread_attr_freeres (void) attribute_hidden;

OK.

>  
>  /* Size and alignment of static TLS block.  */
>  extern size_t __static_tls_size attribute_hidden;
> diff --git a/nptl/pthread_setattr_default_np.c b/nptl/pthread_setattr_default_np.c
> index c4cfb4e8ef..7a1c644334 100644
> --- a/nptl/pthread_setattr_default_np.c
> +++ b/nptl/pthread_setattr_default_np.c
> @@ -81,3 +81,13 @@ pthread_setattr_default_np (const pthread_attr_t *in)
>    lll_unlock (__default_pthread_attr_lock, LLL_PRIVATE);
>    return ret;
>  }
> +
> +/* This is placed in the same file as pthread_setattr_default_np
> +   because only this function can trigger allocation of attribute
> +   data.  This way, the function is automatically defined for all the
> +   cases when it is needed in static builds.  */
> +void
> +__default_pthread_attr_freeres (void)
> +{
> +  __pthread_attr_destroy (&__default_pthread_attr.external);

OK. Delete any internally allocated memory.

> +}
>
diff mbox series

Patch

diff --git a/nptl/nptlfreeres.c b/nptl/nptlfreeres.c
index dda11e5922..07aa34adfa 100644
--- a/nptl/nptlfreeres.c
+++ b/nptl/nptlfreeres.c
@@ -25,6 +25,7 @@ 
 void
 __libpthread_freeres (void)
 {
+  call_function_static_weak (__default_pthread_attr_freeres);
   call_function_static_weak (__nptl_stacks_freeres);
   call_function_static_weak (__shm_directory_freeres);
   call_function_static_weak (__nptl_unwind_freeres);
diff --git a/nptl/pthreadP.h b/nptl/pthreadP.h
index acc8e88e4a..ed30b72923 100644
--- a/nptl/pthreadP.h
+++ b/nptl/pthreadP.h
@@ -201,6 +201,8 @@  enum
 /* Default pthread attributes.  */
 extern union pthread_attr_transparent __default_pthread_attr attribute_hidden;
 extern int __default_pthread_attr_lock attribute_hidden;
+/* Called from __libpthread_freeres to deallocate the default attribute.  */
+extern void __default_pthread_attr_freeres (void) attribute_hidden;
 
 /* Size and alignment of static TLS block.  */
 extern size_t __static_tls_size attribute_hidden;
diff --git a/nptl/pthread_setattr_default_np.c b/nptl/pthread_setattr_default_np.c
index c4cfb4e8ef..7a1c644334 100644
--- a/nptl/pthread_setattr_default_np.c
+++ b/nptl/pthread_setattr_default_np.c
@@ -81,3 +81,13 @@  pthread_setattr_default_np (const pthread_attr_t *in)
   lll_unlock (__default_pthread_attr_lock, LLL_PRIVATE);
   return ret;
 }
+
+/* This is placed in the same file as pthread_setattr_default_np
+   because only this function can trigger allocation of attribute
+   data.  This way, the function is automatically defined for all the
+   cases when it is needed in static builds.  */
+void
+__default_pthread_attr_freeres (void)
+{
+  __pthread_attr_destroy (&__default_pthread_attr.external);
+}