Do not leak AuthRequest structs for clients who fail registration.
authorMichael Poole <mdpoole@troilus.org>
Thu, 6 Jul 2006 03:45:04 +0000 (03:45 +0000)
committerMichael Poole <mdpoole@troilus.org>
Thu, 6 Jul 2006 03:45:04 +0000 (03:45 +0000)
git-svn-id: file:///home/klmitch/undernet-ircu/undernet-ircu-svn/ircu2/branches/u2_10_12_branch@1692 c9e4aea6-c8fd-4c43-8297-357d70d61c8c

ChangeLog
ircd/s_auth.c

index 41d805c0f7066c191621760b10f01a022d1fb1fd..078d68a62634ac4d4947625cb65055d373f33975 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2006-07-05  Michael Poole <mdpoole@troilus.org>
+
+       * ircd/s_auth.c (auth_freelist): New static variable.
+       (check_auth_finished): Move call to destroy_auth_request().
+       (destroy_auth_request): Prepend auth request to freelist.
+       (start_auth): Use struct from auth freelist if possible.
+
 2006-06-30  Michael Poole <mdpoole@troilus.org>
 
        * ircd/ircd_parser.y (iauth*): Avoid leaking program name string.
index f0b331cdfd16232b7756dd8184e8c7486b90a506..7984b5df8bd205219f00ecf7b505d4b7197ddde6 100644 (file)
@@ -200,7 +200,9 @@ struct IAuth {
 #define i_debug(iauth) ((iauth)->i_debug)
 
 /** Active instance of IAuth. */
-struct IAuth *iauth;
+static struct IAuth *iauth;
+/** Freelist of AuthRequest structures. */
+static struct AuthRequest *auth_freelist;
 
 static void iauth_sock_callback(struct Event *ev);
 static void iauth_stderr_callback(struct Event *ev);
@@ -425,7 +427,6 @@ static int check_auth_finished(struct AuthRequest *auth)
   else
     FlagSet(&auth->flags, AR_IAUTH_HURRY);
 
-  destroy_auth_request(auth);
   if (IsUserPort(auth->client))
   {
     memset(cli_passwd(auth->client), 0, sizeof(cli_passwd(auth->client)));
@@ -435,7 +436,8 @@ static int check_auth_finished(struct AuthRequest *auth)
   }
   else
     res = 0;
-  MyFree(auth);
+  if (res == 0)
+    destroy_auth_request(auth);
   return res;
 }
 
@@ -723,7 +725,10 @@ void destroy_auth_request(struct AuthRequest* auth)
 
   if (t_active(&auth->timeout))
     timer_del(&auth->timeout);
+
   cli_auth(auth->client) = NULL;
+  auth->next = auth_freelist;
+  auth_freelist = auth;
 }
 
 /** Handle a 'ping' (authorization) timeout for a client.
@@ -966,8 +971,13 @@ void start_auth(struct Client* client)
   socket_events(&(cli_socket(client)), SOCK_ACTION_SET | SOCK_EVENT_READABLE);
 
   /* Allocate the AuthRequest. */
-  auth = MyCalloc(1, sizeof(*auth));
+  auth = auth_freelist;
+  if (auth)
+      auth_freelist = auth->next;
+  else
+      auth = MyMalloc(sizeof(*auth));
   assert(0 != auth);
+  memset(auth, 0, sizeof(*auth));
   auth->client = client;
   cli_auth(client) = auth;
   s_fd(&auth->socket) = -1;