Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dangling pointer in pthread_join?

According to this, pthread_join sets the output parameter **thread_return to pd->result, then frees pd. Is this okay and I am missing something, or is there a serious bug in glibc?

    /* We mark the thread as terminated and as joined.  */
    pd->tid = -1;

    /* Store the return value if the caller is interested.  */
    if (thread_return != NULL)
      *thread_return = pd->result;


    /* Free the TCB.  */
    __free_tcb (pd);
like image 308
danuker Avatar asked Nov 28 '25 02:11

danuker


1 Answers

__free_tbc does not free pd, but the thread's stack, ie pd->tpp (see also here). So pd->result still a valid pointer after these statements.

like image 55
md5 Avatar answered Nov 30 '25 15:11

md5



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!