[PATCH v3] stdlib: Fix qsort memory leak if callback throws (BZ 32058)

Florian Weimer fweimer@redhat.com
Thu Mar 27 08:37:53 GMT 2025


* Adhemerval Zanella:

> diff --git a/sysdeps/htl/pthreadP.h b/sysdeps/htl/pthreadP.h
> index cf8a2efe86..ef1fa8ca95 100644
> --- a/sysdeps/htl/pthreadP.h
> +++ b/sysdeps/htl/pthreadP.h
> @@ -23,6 +23,7 @@
>  
>  #include <pthread.h>
>  #include <link.h>
> +#include <bits/cancelation.h>
>  
>  /* Attribute to indicate thread creation was issued from C11 thrd_create.  */
>  #define ATTR_C11_THREAD ((void*)(uintptr_t)-1)
> @@ -113,4 +114,11 @@ hidden_proto (__pthread_get_cleanup_stack)
>    _Static_assert (sizeof (type) == size,				\
>  		  "sizeof (" #type ") != " #size)
>  
> +#ifndef pthread_cleanup_combined_push
> +# define pthread_cleanup_combined_push  __pthread_cleanup_push
> +#endif
> +#ifndef pthread_cleanup_combined_pop
> +# define pthread_cleanup_combined_pop   __pthread_cleanup_pop
> +#endif

This does not fix the exception handling bug on Hurd because Hurd does
not perform combined pushes.

Maybe the Hurd maintainers can help to implement something similar to
what we have in sysdeps/nptl/pthreadP.h?  Or you could mention this in
comments.

This comment in sysdeps/nptl/pthreadP.h should be updated because it's
not just for pthread_once anymore:

/* Special cleanup macros which register cleanup both using
   __pthread_cleanup_{push,pop} and using cleanup attribute.  This is needed
   for pthread_once, so that it supports both throwing exceptions from the
   pthread_once callback (only cleanup attribute works there) and cancellation
   of the thread running the callback if the callback or some routines it
   calls don't have unwind information.  */


Thanks,
Florian



More information about the Libc-alpha mailing list