Question: why does this code segfault? void searchDirectory(void path) char base(char *)path; printf( %s , base) ; DIR *dir opendir(base); struct dirent *newfile; char buf

why does this code segfault? void searchDirectory(void path) char base(char *)path; printf(why does this code segfault?

void searchDirectory(void path) char base(char *)path; printf( "%s " , base) ; DIR *dir opendir(base); struct dirent *newfile; char buf [2048]0 while( (newfile -readdir(dir)) NULL) // regular files if (newfile->d_typeDT_REG) else if (newfile->d_typeDTDIR)// folders if ( ! strp (newfile--d name,".") | | ! strpnewfile--d name,'..") ){ continue; if (strcmp (base,"./")) I/.name> .ame sprintf(buf, "%s%s ", base, newfile->d_name); while (pthread mutex_lock(&mallocThread)1 pNode *node malloc(sizeof (struct pNode)); pthread_mutex_unlock(&mallocThread); pthread_create(&(node->threadID), NULL, &searchDirectory, (void*) buf); addToJoinLockLink(node); //searchDirectory ((void *)buf); else /ame/test alex -> .ame/test/alex sprintf(buf, "%s/%s" , base, newfile->d_name); while (pthread mutex_lock &mallocThread)11 pNode node-malloc(sizeof (struct pNode)); pthread mutex unlock (&mallocThread); //searchDirectory( (void *)buf) pthread_create(&(node->threadID), NULL, &searchDirectory, (void*) buf); addToJoinLockLink (node); pthread exit(NULL)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!