gnunet-svn
[Top][All Lists]
Advanced

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

[libmicrohttpd] 01/02: MHD_ip_limit_add(): do not use syscalls while hol


From: gnunet
Subject: [libmicrohttpd] 01/02: MHD_ip_limit_add(): do not use syscalls while holding the lock
Date: Mon, 31 Jan 2022 16:34:44 +0100

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

karlson2k pushed a commit to branch master
in repository libmicrohttpd.

commit 464d174103165453f149141d505ec8a09cc2fb17
Author: Evgeny Grin (Karlson2k) <k2k@narod.ru>
AuthorDate: Mon Jan 31 18:29:45 2022 +0300

    MHD_ip_limit_add(): do not use syscalls while holding the lock
---
 src/microhttpd/daemon.c | 44 +++++++++++++++++++++++---------------------
 1 file changed, 23 insertions(+), 21 deletions(-)

diff --git a/src/microhttpd/daemon.c b/src/microhttpd/daemon.c
index 47fe742d..587000de 100644
--- a/src/microhttpd/daemon.c
+++ b/src/microhttpd/daemon.c
@@ -378,9 +378,9 @@ MHD_ip_limit_add (struct MHD_Daemon *daemon,
                   const struct sockaddr *addr,
                   socklen_t addrlen)
 {
-  struct MHD_IPCount *key;
-  void **nodep;
-  void *node;
+  struct MHD_IPCount *newkeyp;
+  struct MHD_IPCount *keyp;
+  struct MHD_IPCount **nodep;
   enum MHD_Result result;
 
   daemon = MHD_get_master (daemon);
@@ -388,45 +388,47 @@ MHD_ip_limit_add (struct MHD_Daemon *daemon,
   if (0 == daemon->per_ip_connection_limit)
     return MHD_YES;
 
-  if (NULL == (key = malloc (sizeof(*key))))
+  newkeyp = (struct MHD_IPCount *) malloc (sizeof(struct MHD_IPCount));
+  if (NULL == newkeyp)
     return MHD_NO;
 
   /* Initialize key */
   if (MHD_NO == MHD_ip_addr_to_key (addr,
                                     addrlen,
-                                    key))
+                                    newkeyp))
   {
-    /* Allow unhandled address types through */
-    free (key);
-    return MHD_YES;
+    free (newkeyp);
+    return MHD_YES; /* Allow unhandled address types through */
   }
+
   MHD_ip_count_lock (daemon);
 
   /* Search for the IP address */
-  if (NULL == (nodep = tsearch (key,
-                                &daemon->per_ip_connection_count,
-                                &MHD_ip_addr_compare)))
+  nodep = (struct MHD_IPCount **) tsearch (newkeyp,
+                                           &daemon->per_ip_connection_count,
+                                           &MHD_ip_addr_compare);
+  if (NULL == nodep)
   {
+    MHD_ip_count_unlock (daemon);
+    free (newkeyp);
 #ifdef HAVE_MESSAGES
     MHD_DLOG (daemon,
               _ ("Failed to add IP connection count node.\n"));
 #endif
-    MHD_ip_count_unlock (daemon);
-    free (key);
     return MHD_NO;
   }
-  node = *nodep;
-  /* If we got an existing node back, free the one we created */
-  if (node != key)
-    free (key);
-  key = (struct MHD_IPCount *) node;
+  keyp = *nodep;
   /* Test if there is room for another connection; if so,
    * increment count */
-  result = (key->count < daemon->per_ip_connection_limit) ? MHD_YES : MHD_NO;
+  result = (keyp->count < daemon->per_ip_connection_limit) ? MHD_YES : MHD_NO;
   if (MHD_NO != result)
-    ++key->count;
-
+    ++keyp->count;
   MHD_ip_count_unlock (daemon);
+
+  /* If we got an existing node back, free the one we created */
+  if (keyp != newkeyp)
+    free (newkeyp);
+
   return result;
 }
 

-- 
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]