title: segmentation fault with accept() on linux
body: <p>I have a problem with a client/server programm on linux. 
  I wrote a server programm wich is sending data cyclic to one conneted client. 
  Now I want to detect, if the client close the connection to the server. When the connection is closed from the client, i want to wait with accept(...) for an new connection.
  Here the critical parts of my code:</p>
  
  <pre><code>error = send(client_sock, Zeichen, 1, MSG_NOSIGNAL);
  if(error &lt; 0)
  {
      connected = 0;
      printf("Error, write on TCP Socket failed!!! Reconnecting... \r\n");
      close(serverSocket);
      initServer();
  }
  
  int initServer(void)
  {
      int *new_sock;
      socklen_t size;
      struct sockaddr_in server, client;
  
      serverSocket = socket(AF_INET , SOCK_STREAM , 0);       //Create socket
      if (serverSocket == -1)
      {
        printf("Could not create socket \r\n");
        return 0;
      }else
      {
        printf("Socket created \r\n");
      }
  
      server.sin_addr.s_addr = inet_addr(IPAdresse);
      server.sin_family = AF_INET;
      server.sin_port = htons(TCPPort);
  
      if(bind(serverSocket,(struct sockaddr *)&amp;server , sizeof(server)) &lt; 0)  
      {
        printf("bind failed. Error \r\n");
        return 0;
      }else
      {
        printf("bind done \r\n");
      }
  
      listen(serverSocket, 1);        
      printf("Waiting for incoming connections... \r\n");
      size = sizeof(sockaddr_in);
      printf("size of sockaddr_in: %i \r\n", size);
      client_sock = accept(serverSocket, (struct sockaddr *)&amp;client, &amp;size);
  
     if (client_sock &lt; 0)
     {
       printf("accept failed \r\n");
       return 0;
     }else
     {
      connected = 1;
      return 1;
     }
  }
  </code></pre>
  
  <p>The first time it works fine, I can connect and can send data over the socket. When the client close the connection the error is detected, I close the socket an start the server again to wait for a new connection. But than I get a segmentation fault when I do the accept(..) for the second time!!! 
  Can someone help me please!!! Thanks a lot!</p>