LogoopenSUSE Build Service > Projects
Sign Up | Log In

View File atftp-0.7_thread_crash.patch of Package atftp (Project home:vitezslav_cizek:branches:network)

http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=271816
Index: tftpd.c
===================================================================
--- tftpd.c.orig
+++ tftpd.c
@@ -157,6 +157,7 @@ int main(int argc, char **argv)
      struct servent *serv;
      struct passwd *user;
      struct group *group;
+     pthread_t tid;
 
 #ifdef HAVE_MTFTP
      pthread_t mtftp_thread;
@@ -466,7 +467,7 @@ int main(int argc, char **argv)
                new->client_info->next = NULL;
                
                /* Start a new server thread. */
-               if (pthread_create(&new->tid, NULL, tftpd_receive_request,
+               if (pthread_create(&tid, NULL, tftpd_receive_request,
                                   (void *)new) != 0)
                {
                     logger(LOG_ERR, "Failed to start new thread");
@@ -567,7 +568,8 @@ void *tftpd_receive_request(void *arg)
 
      /* Detach ourself. That way the main thread does not have to
       * wait for us with pthread_join. */
-     pthread_detach(pthread_self());
+     data->tid = pthread_self();
+     pthread_detach(data->tid);
 
      /* Read the first packet from stdin. */
      data_size = data->data_buffer_size;     
@@ -733,7 +735,7 @@ void *tftpd_receive_request(void *arg)
 
      /* free the thread structure */
      free(data);
-     
+
      logger(LOG_INFO, "Server thread exiting");
      pthread_exit(NULL);
 }