changeset 1148:b5b172ab0ed9 HEAD

Make sure calling client_destroy() multiple times doesn't break anything.
author Timo Sirainen <tss@iki.fi>
date Tue, 11 Feb 2003 18:56:35 +0200
parents 0beeeffc6d31
children 38f6130abec2
files src/imap-login/client.c src/imap-login/client.h src/pop3-login/client.c src/pop3-login/client.h
diffstat 4 files changed, 14 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/src/imap-login/client.c	Tue Feb 11 18:53:14 2003 +0200
+++ b/src/imap-login/client.c	Tue Feb 11 18:56:35 2003 +0200
@@ -362,12 +362,18 @@
 
 void client_destroy(struct imap_client *client, const char *reason)
 {
+	if (client->destroyed)
+		return;
+	client->destroyed = TRUE;
+
 	if (reason != NULL)
 		client_syslog(client, reason);
 
 	hash_remove(clients, client);
 
 	imap_parser_destroy(client->parser);
+	client->parser = NULL;
+
 	i_stream_close(client->input);
 	o_stream_close(client->output);
 
@@ -381,7 +387,6 @@
 		client->common.fd = -1;
 	}
 
-	i_free(client->common.virtual_user);
 	client_unref(client);
 }
 
@@ -399,6 +404,7 @@
 	o_stream_unref(client->output);
 
 	buffer_free(client->plain_login);
+	i_free(client->common.virtual_user);
 	i_free(client);
 
 	main_unref();
--- a/src/imap-login/client.h	Tue Feb 11 18:53:14 2003 +0200
+++ b/src/imap-login/client.h	Tue Feb 11 18:56:35 2003 +0200
@@ -25,6 +25,7 @@
 	unsigned int tls:1;
 	unsigned int cmd_finished:1;
 	unsigned int skip_line:1;
+	unsigned int destroyed:1;
 };
 
 struct client *client_create(int fd, struct ip_addr *ip, int ssl);
--- a/src/pop3-login/client.c	Tue Feb 11 18:53:14 2003 +0200
+++ b/src/pop3-login/client.c	Tue Feb 11 18:56:35 2003 +0200
@@ -261,6 +261,10 @@
 
 void client_destroy(struct pop3_client *client, const char *reason)
 {
+	if (client->destroyed)
+		return;
+	client->destroyed = TRUE;
+
 	if (reason != NULL)
 		client_syslog(client, reason);
 
@@ -277,7 +281,6 @@
 	net_disconnect(client->common.fd);
 	client->common.fd = -1;
 
-	i_free(client->common.virtual_user);
 	client_unref(client);
 }
 
@@ -295,6 +298,7 @@
 	o_stream_unref(client->output);
 
 	buffer_free(client->plain_login);
+	i_free(client->common.virtual_user);
 	i_free(client);
 
 	main_unref();
--- a/src/pop3-login/client.h	Tue Feb 11 18:53:14 2003 +0200
+++ b/src/pop3-login/client.h	Tue Feb 11 18:56:35 2003 +0200
@@ -20,6 +20,7 @@
 	buffer_t *plain_login;
 
 	unsigned int tls:1;
+	unsigned int destroyed:1;
 };
 
 struct client *client_create(int fd, struct ip_addr *ip, int ssl);