Subj : Segmentation fault when using malloc with threads To : comp.programming.threads From : Karthik007 Date : Sun Feb 27 2005 06:08 am Hi!! I am writing a client/server application for file transfer. The server is a concurrent server implemented on threads concept. I have pasted some code snippets from the server program. main() { pthread_t srvThread[10]; struct control data[10]; int cliNum = 0; while(1) { puts("\nServer Waiting.......\n"); recvmsg(); sendmsg(); if(userAuthenticate() == SUCCESS) { if(sock_fd == -1) { perror(); continue; } else { cliNum++; data[cliNum] = data[0]; pthread_create(&srvThread[cliNum],NULL,handleRequest,(void *)&data[cliNum]); } } } } void *handleRequest(void *arg) { struct control *info; info = (struct control *)malloc(sizeof(struct control)); bzero(info, sizeof(struct control)); info = (struct control *) arg; info->status = 0; pthread_detach(pthread_self()); do { }while( ); close(info->sock_fd); free(info); return NULL; } The problem is when i connect the server from a client it works fine and when i connect additional clients with "atleast one client already connected" the program works fine, but when a client has connects and then disconnects aafter which i try to connect a new client the malloc() call fails giving a "Segmentation fault" error. The system i am running this program is a P4 with 256MB RAM and the OS is fedora core 2. I request you kind help in solving this problem. Thanking you in advance Karthik .