From: Michael Poole Date: Thu, 6 Jul 2006 03:45:04 +0000 (+0000) Subject: Do not leak AuthRequest structs for clients who fail registration. X-Git-Url: http://git.pk910.de/?p=ircu2.10.12-pk.git;a=commitdiff_plain;h=479607167274e9cd930488119f6552648f321059 Do not leak AuthRequest structs for clients who fail registration. git-svn-id: file:///home/klmitch/undernet-ircu/undernet-ircu-svn/ircu2/branches/u2_10_12_branch@1692 c9e4aea6-c8fd-4c43-8297-357d70d61c8c --- diff --git a/ChangeLog b/ChangeLog index 41d805c..078d68a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2006-07-05 Michael Poole + + * 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 * ircd/ircd_parser.y (iauth*): Avoid leaking program name string. diff --git a/ircd/s_auth.c b/ircd/s_auth.c index f0b331c..7984b5d 100644 --- a/ircd/s_auth.c +++ b/ircd/s_auth.c @@ -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;