gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[libmicrohttpd] branch master updated (b9ed765c -> 05f582d4)


From: gnunet
Subject: [libmicrohttpd] branch master updated (b9ed765c -> 05f582d4)
Date: Thu, 12 May 2022 15:42:18 +0200

This is an automated email from the git hooks/post-receive script.

karlson2k pushed a change to branch master
in repository libmicrohttpd.

    from b9ed765c Fixed compiler error introduced by 
cd5ad7aaadd8f169f79ba3564d49d7f2889093b8
     new 5ea2a8e6 Cosmetics for cd5ad7aaadd8f169f79ba3564d49d7f2889093b8
     new c1a1826e Enforced no use of 'per_ip_connection_mutex' in slave daemons
     new 2590e0e8 MHD_set_connection_option(): reduced lock scope
     new 1619fda1 Added asserts to check for non-master daemons only
     new 05f582d4 Fixed leaks of mutexes.

The 5 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 src/microhttpd/connection.c | 61 ++++++++++++++--------------
 src/microhttpd/daemon.c     | 97 ++++++++++++++++++++++++++++-----------------
 2 files changed, 91 insertions(+), 67 deletions(-)

diff --git a/src/microhttpd/connection.c b/src/microhttpd/connection.c
index 93408eb7..ab659064 100644
--- a/src/microhttpd/connection.c
+++ b/src/microhttpd/connection.c
@@ -3714,6 +3714,9 @@ void
 MHD_update_last_activity_ (struct MHD_Connection *connection)
 {
   struct MHD_Daemon *daemon = connection->daemon;
+#if defined(MHD_USE_THREADS)
+  mhd_assert (NULL == daemon->worker_pool);
+#endif /* MHD_USE_THREADS */
 
   if (0 == connection->connection_timeout_ms)
     return;  /* Skip update of activity for connections
@@ -4307,6 +4310,7 @@ cleanup_connection (struct MHD_Connection *connection)
 #ifdef MHD_USE_THREADS
   mhd_assert ( (0 == (daemon->options & MHD_USE_INTERNAL_POLLING_THREAD)) || \
                MHD_thread_ID_match_current_ (connection->pid) );
+  mhd_assert (NULL == daemon->worker_pool);
 #endif /* MHD_USE_THREADS */
 
   if (connection->in_cleanup)
@@ -5107,21 +5111,6 @@ MHD_set_connection_option (struct MHD_Connection 
*connection,
   case MHD_CONNECTION_OPTION_TIMEOUT:
     if (0 == connection->connection_timeout_ms)
       connection->last_activity = MHD_monotonic_msec_counter ();
-#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
-    MHD_mutex_lock_chk_ (&daemon->cleanup_connection_mutex);
-#endif
-    if ( (0 == (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) &&
-         (! connection->suspended) )
-    {
-      if (connection->connection_timeout_ms == daemon->connection_timeout_ms)
-        XDLL_remove (daemon->normal_timeout_head,
-                     daemon->normal_timeout_tail,
-                     connection);
-      else
-        XDLL_remove (daemon->manual_timeout_head,
-                     daemon->manual_timeout_tail,
-                     connection);
-    }
     va_start (ap, option);
     ui_val = va_arg (ap, unsigned int);
     va_end (ap);
@@ -5138,24 +5127,36 @@ MHD_set_connection_option (struct MHD_Connection 
*connection,
 #endif
       ui_val = UINT64_MAX / 4000 - 1;
     }
-    else
 #endif /* (SIZEOF_UINT64_T - 2) <= SIZEOF_UNSIGNED_INT */
-    connection->connection_timeout_ms = ui_val * 1000;
-    if ( (0 == (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) &&
-         (! connection->suspended) )
+    if (0 == (daemon->options & MHD_USE_THREAD_PER_CONNECTION))
     {
-      if (connection->connection_timeout_ms == daemon->connection_timeout_ms)
-        XDLL_insert (daemon->normal_timeout_head,
-                     daemon->normal_timeout_tail,
-                     connection);
-      else
-        XDLL_insert (daemon->manual_timeout_head,
-                     daemon->manual_timeout_tail,
-                     connection);
-    }
-#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
-    MHD_mutex_unlock_chk_ (&daemon->cleanup_connection_mutex);
+#if defined(MHD_USE_THREADS)
+      MHD_mutex_lock_chk_ (&daemon->cleanup_connection_mutex);
+#endif
+      if (! connection->suspended)
+      {
+        if (connection->connection_timeout_ms == daemon->connection_timeout_ms)
+          XDLL_remove (daemon->normal_timeout_head,
+                       daemon->normal_timeout_tail,
+                       connection);
+        else
+          XDLL_remove (daemon->manual_timeout_head,
+                       daemon->manual_timeout_tail,
+                       connection);
+        connection->connection_timeout_ms = ui_val * 1000;
+        if (connection->connection_timeout_ms == daemon->connection_timeout_ms)
+          XDLL_insert (daemon->normal_timeout_head,
+                       daemon->normal_timeout_tail,
+                       connection);
+        else
+          XDLL_insert (daemon->manual_timeout_head,
+                       daemon->manual_timeout_tail,
+                       connection);
+      }
+#if defined(MHD_USE_THREADS)
+      MHD_mutex_unlock_chk_ (&daemon->cleanup_connection_mutex);
 #endif
+    }
     return MHD_YES;
   default:
     return MHD_NO;
diff --git a/src/microhttpd/daemon.c b/src/microhttpd/daemon.c
index e1bc4812..b7980460 100644
--- a/src/microhttpd/daemon.c
+++ b/src/microhttpd/daemon.c
@@ -260,6 +260,7 @@ struct MHD_IPCount
 static void
 MHD_ip_count_lock (struct MHD_Daemon *daemon)
 {
+  mhd_assert (NULL == daemon->master);
 #if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
   MHD_mutex_lock_chk_ (&daemon->per_ip_connection_mutex);
 #else
@@ -276,6 +277,7 @@ MHD_ip_count_lock (struct MHD_Daemon *daemon)
 static void
 MHD_ip_count_unlock (struct MHD_Daemon *daemon)
 {
+  mhd_assert (NULL == daemon->master);
 #if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
   MHD_mutex_unlock_chk_ (&daemon->per_ip_connection_mutex);
 #else
@@ -2730,6 +2732,7 @@ new_connection_process_ (struct MHD_Daemon *daemon,
    * must be called only within daemon thread. */
   mhd_assert ( (0 == (daemon->options & MHD_USE_INTERNAL_POLLING_THREAD)) || \
                MHD_thread_ID_match_current_ (daemon->pid) );
+  mhd_assert (NULL == daemon->worker_pool);
 #endif /* MHD_USE_THREADS */
 
   /* Allocate memory pool in the processing thread so
@@ -3077,6 +3080,7 @@ void
 internal_suspend_connection_ (struct MHD_Connection *connection)
 {
   struct MHD_Daemon *daemon = connection->daemon;
+  mhd_assert (NULL == daemon->worker_pool);
 
 #if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
   mhd_assert ( (0 == (daemon->options & MHD_USE_INTERNAL_POLLING_THREAD)) || \
@@ -3221,6 +3225,9 @@ _MHD_EXTERN void
 MHD_resume_connection (struct MHD_Connection *connection)
 {
   struct MHD_Daemon *daemon = connection->daemon;
+#if defined(MHD_USE_THREADS)
+  mhd_assert (NULL == daemon->worker_pool);
+#endif /* MHD_USE_THREADS */
 
   if (0 == (daemon->options & MHD_TEST_ALLOW_SUSPEND_RESUME))
     MHD_PANIC (_ (
@@ -3597,6 +3604,7 @@ MHD_accept_connection (struct MHD_Daemon *daemon)
 #ifdef MHD_USE_THREADS
   mhd_assert ( (0 == (daemon->options & MHD_USE_INTERNAL_POLLING_THREAD)) || \
                MHD_thread_ID_match_current_ (daemon->pid) );
+  mhd_assert (NULL == daemon->worker_pool);
 #endif /* MHD_USE_THREADS */
 
   addrlen = sizeof (addrstorage);
@@ -3777,6 +3785,7 @@ MHD_cleanup_connections (struct MHD_Daemon *daemon)
 #if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
   mhd_assert ( (0 == (daemon->options & MHD_USE_INTERNAL_POLLING_THREAD)) || \
                MHD_thread_ID_match_current_ (daemon->pid) );
+  mhd_assert (NULL == daemon->worker_pool);
 
   MHD_mutex_lock_chk_ (&daemon->cleanup_connection_mutex);
 #endif
@@ -5495,6 +5504,7 @@ close_connection (struct MHD_Connection *pos)
 #ifdef MHD_USE_THREADS
   mhd_assert ( (0 == (daemon->options & MHD_USE_INTERNAL_POLLING_THREAD)) || \
                MHD_thread_ID_match_current_ (daemon->pid) );
+  mhd_assert (NULL == daemon->worker_pool);
 #endif /* MHD_USE_THREADS */
 
   if (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION))
@@ -7279,19 +7289,6 @@ MHD_start_daemon_va (unsigned int flags,
 #ifdef HAVE_MESSAGES
     MHD_DLOG (daemon,
               _ ("MHD failed to initialize IP connection limit mutex.\n"));
-#endif
-    if (MHD_INVALID_SOCKET != listen_fd)
-      MHD_socket_close_chk_ (listen_fd);
-    goto free_and_fail;
-  }
-  if (! MHD_mutex_init_ (&daemon->cleanup_connection_mutex))
-  {
-#ifdef HAVE_MESSAGES
-    MHD_DLOG (daemon,
-              _ ("MHD failed to initialize IP connection limit mutex.\n"));
-#endif
-#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
-    MHD_mutex_destroy_chk_ (&daemon->cleanup_connection_mutex);
 #endif
     if (MHD_INVALID_SOCKET != listen_fd)
       MHD_socket_close_chk_ (listen_fd);
@@ -7311,7 +7308,6 @@ MHD_start_daemon_va (unsigned int flags,
     if (MHD_INVALID_SOCKET != listen_fd)
       MHD_socket_close_chk_ (listen_fd);
 #if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
-    MHD_mutex_destroy_chk_ (&daemon->cleanup_connection_mutex);
     MHD_mutex_destroy_chk_ (&daemon->per_ip_connection_mutex);
 #endif
     goto free_and_fail;
@@ -7335,14 +7331,25 @@ MHD_start_daemon_va (unsigned int flags,
 #endif /* ! HAVE_LISTEN_SHUTDOWN */
     if (0 == daemon->worker_pool_size)
     {
+      if (! MHD_mutex_init_ (&daemon->cleanup_connection_mutex))
+      {
+#ifdef HAVE_MESSAGES
+        MHD_DLOG (daemon,
+                  _ ("Failed to initialise internal lists mutex.\n"));
+#endif
+        MHD_mutex_destroy_chk_ (&daemon->per_ip_connection_mutex);
+        if (MHD_INVALID_SOCKET != listen_fd)
+          MHD_socket_close_chk_ (listen_fd);
+        goto free_and_fail;
+      }
       if (! MHD_mutex_init_ (&daemon->new_connections_mutex))
       {
 #ifdef HAVE_MESSAGES
         MHD_DLOG (daemon,
                   _ ("Failed to initialise mutex.\n"));
 #endif
-        MHD_mutex_destroy_chk_ (&daemon->cleanup_connection_mutex);
         MHD_mutex_destroy_chk_ (&daemon->per_ip_connection_mutex);
+        MHD_mutex_destroy_chk_ (&daemon->cleanup_connection_mutex);
         if (MHD_INVALID_SOCKET != listen_fd)
           MHD_socket_close_chk_ (listen_fd);
         goto free_and_fail;
@@ -7369,8 +7376,8 @@ MHD_start_daemon_va (unsigned int flags,
                   MHD_strerror_ (errno));
 #endif /* HAVE_MESSAGES */
         MHD_mutex_destroy_chk_ (&daemon->new_connections_mutex);
-        MHD_mutex_destroy_chk_ (&daemon->cleanup_connection_mutex);
         MHD_mutex_destroy_chk_ (&daemon->per_ip_connection_mutex);
+        MHD_mutex_destroy_chk_ (&daemon->cleanup_connection_mutex);
         if (MHD_INVALID_SOCKET != listen_fd)
           MHD_socket_close_chk_ (listen_fd);
         goto free_and_fail;
@@ -7408,12 +7415,21 @@ MHD_start_daemon_va (unsigned int flags,
         d->master = daemon;
         d->worker_pool_size = 0;
         d->worker_pool = NULL;
+        if (! MHD_mutex_init_ (&d->cleanup_connection_mutex))
+        {
+#ifdef HAVE_MESSAGES
+          MHD_DLOG (daemon,
+                    _ ("Failed to initialise internal lists mutex.\n"));
+#endif
+          goto thread_failed;
+        }
         if (! MHD_mutex_init_ (&d->new_connections_mutex))
         {
-  #ifdef HAVE_MESSAGES
+#ifdef HAVE_MESSAGES
           MHD_DLOG (daemon,
                     _ ("Failed to initialise mutex.\n"));
-  #endif
+#endif
+          MHD_mutex_destroy_chk_ (&d->cleanup_connection_mutex);
           goto thread_failed;
         }
         if (0 != (*pflags & MHD_USE_ITC))
@@ -7427,6 +7443,7 @@ MHD_start_daemon_va (unsigned int flags,
                       MHD_itc_last_strerror_ () );
 #endif
             MHD_mutex_destroy_chk_ (&d->new_connections_mutex);
+            MHD_mutex_destroy_chk_ (&d->cleanup_connection_mutex);
             goto thread_failed;
           }
           if ( (0 == (*pflags & (MHD_USE_POLL | MHD_USE_EPOLL))) &&
@@ -7438,8 +7455,9 @@ MHD_start_daemon_va (unsigned int flags,
                       _ (
                         "File descriptor for worker inter-thread communication 
channel exceeds maximum value.\n"));
 #endif
-            MHD_mutex_destroy_chk_ (&d->new_connections_mutex);
             MHD_itc_destroy_chk_ (d->itc);
+            MHD_mutex_destroy_chk_ (&d->new_connections_mutex);
+            MHD_mutex_destroy_chk_ (&d->cleanup_connection_mutex);
             goto thread_failed;
           }
         }
@@ -7466,31 +7484,23 @@ MHD_start_daemon_va (unsigned int flags,
           if (MHD_ITC_IS_VALID_ (d->itc))
             MHD_itc_destroy_chk_ (d->itc);
           MHD_mutex_destroy_chk_ (&d->new_connections_mutex);
+          MHD_mutex_destroy_chk_ (&d->cleanup_connection_mutex);
           goto thread_failed;
         }
 #endif
-        /* Must init cleanup connection mutex for each worker */
-        if (! MHD_mutex_init_ (&d->cleanup_connection_mutex))
-        {
-#ifdef HAVE_MESSAGES
-          MHD_DLOG (daemon,
-                    _ ("MHD failed to initialize cleanup connection 
mutex.\n"));
-#endif
-          if (MHD_ITC_IS_VALID_ (d->itc))
-            MHD_itc_destroy_chk_ (d->itc);
-          MHD_mutex_destroy_chk_ (&d->new_connections_mutex);
-          goto thread_failed;
-        }
         /* Some members must be used only in master daemon */
+#if defined(MHD_USE_THREADS)
+        memset (&d->per_ip_connection_mutex, 1,
+                sizeof(d->per_ip_connection_mutex));
+#endif /* MHD_USE_THREADS */
 #ifdef DAUTH_SUPPORT
         d->nnc = NULL;
         d->nonce_nc_size = 0;
 #if defined(MHD_USE_THREADS)
-        memset (&d->nnc_lock, 1, sizeof(daemon->nnc_lock));
+        memset (&d->nnc_lock, 1, sizeof(d->nnc_lock));
 #endif /* MHD_USE_THREADS */
 #endif /* DAUTH_SUPPORT */
 
-
         /* Spawn the worker thread */
         if (! MHD_create_named_thread_ (&d->pid,
                                         "MHD-worker",
@@ -7517,6 +7527,7 @@ MHD_start_daemon_va (unsigned int flags,
           if (MHD_ITC_IS_VALID_ (d->itc))
             MHD_itc_destroy_chk_ (d->itc);
           MHD_mutex_destroy_chk_ (&d->new_connections_mutex);
+          MHD_mutex_destroy_chk_ (&d->cleanup_connection_mutex);
           goto thread_failed;
         }
       }
@@ -7524,12 +7535,27 @@ MHD_start_daemon_va (unsigned int flags,
   }
   else
   { /* Daemon without internal threads */
+    if (! MHD_mutex_init_ (&daemon->cleanup_connection_mutex))
+    {
+#ifdef HAVE_MESSAGES
+      MHD_DLOG (daemon,
+                _ ("Failed to initialise internal lists mutex.\n"));
+#endif
+      MHD_mutex_destroy_chk_ (&daemon->per_ip_connection_mutex);
+      if (MHD_INVALID_SOCKET != listen_fd)
+        MHD_socket_close_chk_ (listen_fd);
+      goto free_and_fail;
+    }
     if (! MHD_mutex_init_ (&daemon->new_connections_mutex))
     {
 #ifdef HAVE_MESSAGES
       MHD_DLOG (daemon,
                 _ ("Failed to initialise mutex.\n"));
 #endif
+      MHD_mutex_destroy_chk_ (&daemon->cleanup_connection_mutex);
+      MHD_mutex_destroy_chk_ (&daemon->per_ip_connection_mutex);
+      if (MHD_INVALID_SOCKET != listen_fd)
+        MHD_socket_close_chk_ (listen_fd);
       goto free_and_fail;
     }
   }
@@ -7926,16 +7952,12 @@ MHD_stop_daemon (struct MHD_Daemon *daemon)
         MHD_PANIC (_ ("Failed to join a thread.\n"));
       }
       /* close_all_connections() was called in daemon thread. */
-      MHD_mutex_destroy_chk_ (&daemon->new_connections_mutex);
     }
     else
 #endif
     {
       /* No internal threads are used for polling sockets. */
       close_all_connections (daemon);
-#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
-      MHD_mutex_destroy_chk_ (&daemon->new_connections_mutex);
-#endif /* MHD_USE_POSIX_THREADS || MHD_USE_W32_THREADS */
     }
     mhd_assert (NULL == daemon->connections_head);
     mhd_assert (NULL == daemon->cleanup_head);
@@ -7961,6 +7983,7 @@ MHD_stop_daemon (struct MHD_Daemon *daemon)
 
 #if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
     MHD_mutex_destroy_chk_ (&daemon->cleanup_connection_mutex);
+    MHD_mutex_destroy_chk_ (&daemon->new_connections_mutex);
 #endif
   }
 

-- 
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]