changeset 3414:c2497d4c60c9 HEAD

Auth workers were leaking memory for each request. Fixed also a few invalid memory accesses at deinitialization.
author Timo Sirainen <tss@iki.fi>
date Wed, 08 Jun 2005 16:37:17 +0300
parents b0b83a2fba69
children 4e36a99268dd
files src/auth/auth-worker-client.c src/auth/auth-worker-client.h src/auth/main.c
diffstat 3 files changed, 22 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/src/auth/auth-worker-client.c	Mon Jun 06 00:42:22 2005 +0300
+++ b/src/auth/auth-worker-client.c	Wed Jun 08 16:37:17 2005 +0300
@@ -29,8 +29,6 @@
 	struct timeout *to;
 };
 
-static void auth_worker_client_unref(struct auth_worker_client *client);
-
 static void
 auth_worker_client_check_throttle(struct auth_worker_client *client)
 {
@@ -101,9 +99,10 @@
 			str_append_str(str, request->extra_fields);
 	}
 	str_append_c(str, '\n');
+	o_stream_send(client->output, str_data(str), str_len(str));
 
-	o_stream_send(client->output, str_data(str), str_len(str));
-        auth_worker_client_check_throttle(client);
+	auth_request_unref(request);
+	auth_worker_client_check_throttle(client);
 	auth_worker_client_unref(client);
 }
 
@@ -134,6 +133,7 @@
 
 	if (auth_request->user == NULL || auth_request->service == NULL) {
 		i_error("BUG: PASSV had missing parameters");
+		auth_request_unref(auth_request);
 		return;
 	}
 
@@ -141,6 +141,7 @@
 		auth_request->passdb = auth_request->passdb->next;
 		if (auth_request->passdb == NULL) {
 			i_error("BUG: PASSV had invalid passdb num");
+			auth_request_unref(auth_request);
 			return;
 		}
 	}
@@ -169,9 +170,10 @@
 			str_append_str(str, request->extra_fields);
 	}
 	str_append_c(str, '\n');
+	o_stream_send(client->output, str_data(str), str_len(str));
 
-	o_stream_send(client->output, str_data(str), str_len(str));
-        auth_worker_client_check_throttle(client);
+	auth_request_unref(request);
+	auth_worker_client_check_throttle(client);
 	auth_worker_client_unref(client);
 }
 
@@ -204,6 +206,7 @@
 
 	if (auth_request->user == NULL || auth_request->service == NULL) {
 		i_error("BUG: PASSL had missing parameters");
+		auth_request_unref(auth_request);
 		return;
 	}
 
@@ -211,6 +214,7 @@
 		auth_request->passdb = auth_request->passdb->next;
 		if (auth_request->passdb == NULL) {
 			i_error("BUG: PASSL had invalid passdb num");
+			auth_request_unref(auth_request);
 			return;
 		}
 	}
@@ -233,7 +237,9 @@
 	str_append_c(str, '\n');
 
 	o_stream_send(client->output, str_data(str), str_len(str));
-        auth_worker_client_check_throttle(client);
+
+	auth_request_unref(auth_request);
+	auth_worker_client_check_throttle(client);
 	auth_worker_client_unref(client);
 }
 
@@ -253,6 +259,7 @@
 
 	if (auth_request->user == NULL || auth_request->service == NULL) {
 		i_error("BUG: USER had missing parameters");
+		auth_request_unref(auth_request);
 		return;
 	}
 
@@ -260,6 +267,7 @@
 		auth_request->userdb = auth_request->userdb->next;
 		if (auth_request->userdb == NULL) {
 			i_error("BUG: USER had invalid userdb num");
+			auth_request_unref(auth_request);
 			return;
 		}
 	}
@@ -397,14 +405,16 @@
 	client->fd = -1;
 
 	io_loop_stop(ioloop);
-        auth_worker_client_unref(client);
 }
 
-static void auth_worker_client_unref(struct auth_worker_client *client)
+void auth_worker_client_unref(struct auth_worker_client *client)
 {
 	if (--client->refcount > 0)
 		return;
 
+	if (client->fd != -1)
+		auth_worker_client_destroy(client);
+
 	i_stream_unref(client->input);
 	o_stream_unref(client->output);
 	i_free(client);
--- a/src/auth/auth-worker-client.h	Mon Jun 06 00:42:22 2005 +0300
+++ b/src/auth/auth-worker-client.h	Wed Jun 08 16:37:17 2005 +0300
@@ -5,5 +5,6 @@
 
 struct auth_worker_client *auth_worker_client_create(struct auth *auth, int fd);
 void auth_worker_client_destroy(struct auth_worker_client *client);
+void auth_worker_client_unref(struct auth_worker_client *client);
 
 #endif
--- a/src/auth/main.c	Mon Jun 06 00:42:22 2005 +0300
+++ b/src/auth/main.c	Wed Jun 08 16:37:17 2005 +0300
@@ -250,16 +250,16 @@
 		i_warning("Killed with signal %d", lib_signal_kill);
 
 	if (worker_client != NULL)
-		auth_worker_client_destroy(worker_client);
+		auth_worker_client_unref(worker_client);
 	else
 		auth_request_handler_flush_failures();
 
+        auth_worker_server_deinit();
 	auth_master_listeners_deinit();
 	auth_request_handler_deinit();
 	auth_deinit(auth);
 	mech_deinit();
 
-        auth_worker_server_deinit();
         password_schemes_deinit();
 	random_deinit();