[PATCH 3/5] Add single-threaded path to _int_free

DJ Delorie dj@redhat.com
Thu Oct 12 20:29:00 GMT 2017


Wilco Dijkstra <Wilco.Dijkstra@arm.com> writes:
> @@ -4188,24 +4188,29 @@ _int_free (mstate av, mchunkptr p, int have_lock)
>  
>      /* Atomically link P to its fastbin: P->FD = *FB; *FB = P;  */
>      mchunkptr old = *fb, old2;
> -    unsigned int old_idx = ~0u;
> -    do
> +
> +    /* Check that the top of the bin is not the record we are going to
> +       add (i.e., double free).  */
> +    if (__builtin_expect (old == p, 0))
> +      malloc_printerr ("double free or corruption (fasttop)");

By moving this out of the multi-thread loop, you're removing a check
against some of the top chunks in the case where the loop happens more
than once.

> +    if (SINGLE_THREAD_P)
>        {

If you set have_lock to zero here, you can omit the last two chunks of
this patch.



More information about the Libc-alpha mailing list