Follow @Openwall on Twitter for new release announcements and other news
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-ID: <E9B8FCA610BB6249B7C397BE4A01AE19412212@SRVDE355.weidmueller.com>
Date: Tue, 27 Mar 2018 12:00:39 +0000
From: <Salman.Ahmed@...dmueller.com>
To: <musl@...ts.openwall.com>
Subject: segmentation fault on pthread_detach

Hello,

My application using musl libc runs into a seg fault if I call pthread_detach after pthread_join on the same thread. From my understanding pthread_detach should return ESRCH if a previous join was called on a particular thread. That’s the correct behavior I see if I run my program with glibc. But on my LEDE based router I run into the seg fault issue.
The cross compiling toolchain I use is arm_cortex-a9+neon_gcc-5.4.0_musl-1.1.16_eabi. Simple example I used for testing is below.

#include <stdio.h>
#include <errno.h>
#include <stdlib.h>
#include <pthread.h>

void *print_message_function( void *ptr );

int main()
{
     pthread_t thread1, thread2;
     const char *message1 = "Thread 1";
     const char *message2 = "Thread 2";
     int  iret1, iret2;
     int dret1, dret2;

     iret1 = pthread_create( &thread1, NULL, &print_message_function, (void*) message1);
     if(iret1)
     {
         fprintf(stderr,"Error - pthread_create() return code: %d\n",iret1);
         exit(EXIT_FAILURE);
     }

     iret2 = pthread_create( &thread2, NULL, &print_message_function, (void*) message2);
     if(iret2)
     {
         fprintf(stderr,"Error - pthread_create() return code: %d\n",iret2);
         exit(EXIT_FAILURE);
     }

     printf("pthread_create() for thread 1 returns: %d\n",iret1);
     printf("pthread_create() for thread 2 returns: %d\n",iret2);

     pthread_join( thread1, NULL);
     pthread_join( thread2, NULL);

     dret1 =  pthread_detach(thread1);
     if (dret1 == EINVAL) {
          printf("got EINVAL when detaching 1\n");
     }
     if (dret1 ==  ESRCH) {
          printf("got ESRCH when detaching 1\n");
     }
     dret2 = pthread_detach(thread2);
     if (dret2 == EINVAL) {
          printf("got EINVAL when detaching 2\n");
     }
     if (dret2 ==  ESRCH) {
          printf("got ESRCH when detaching 2\n");
     }

     return 0;
}

void *print_message_function( void *ptr )
{
     char *message;
     message = (char *) ptr;
     printf("%s \n", message);
}

Output gotten
pthread_create() for thread 1 returns: 0
Thread 1
pthread_create() for thread 2 returns: 0
Thread 2
Segmentation fault (core dumped)

Regards
Salman
________________________________
Kommanditgesellschaft - Sitz: Detmold - Amtsgericht Lemgo HRA 2790 -
Komplementärin: Weidmüller Interface Führungsgesellschaft mbH -
Sitz: Detmold - Amtsgericht Lemgo HRB 3924;
Geschäftsführer: José Carlos Álvarez Tobar, Elke Eckstein, Jörg Timmermann;
USt-ID-Nr. DE124599660

Content of type "text/html" skipped

Powered by blists - more mailing lists

Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.