dovecot-1.1: client_command_free()/cancel(): Take pointer-to-poi...

dovecot at dovecot.org dovecot at dovecot.org
Thu Mar 20 16:27:03 EET 2008


details:   http://hg.dovecot.org/dovecot-1.1/rev/33d8adcc2d44
changeset: 7431:33d8adcc2d44
user:      Timo Sirainen <tss at iki.fi>
date:      Thu Mar 20 16:26:27 2008 +0200
description:
client_command_free()/cancel(): Take pointer-to-pointer parameter and set it
to NULL to make sure it's not accessed again.

diffstat:

7 files changed, 31 insertions(+), 24 deletions(-)
src/imap/client.c       |   33 ++++++++++++++++++++-------------
src/imap/client.h       |    4 ++--
src/imap/cmd-append.c   |    6 +++---
src/imap/cmd-idle.c     |    2 +-
src/imap/cmd-search.c   |    2 +-
src/imap/cmd-x-cancel.c |    2 +-
src/imap/imap-sync.c    |    6 +++---

diffs (211 lines):

diff -r 2b89ceb0f6af -r 33d8adcc2d44 src/imap/client.c
--- a/src/imap/client.c	Thu Mar 20 15:42:57 2008 +0200
+++ b/src/imap/client.c	Thu Mar 20 16:26:27 2008 +0200
@@ -66,8 +66,9 @@ struct client *client_create(int fd_in, 
 	return client;
 }
 
-void client_command_cancel(struct client_command_context *cmd)
-{
+void client_command_cancel(struct client_command_context **_cmd)
+{
+	struct client_command_context *cmd = *_cmd;
 	bool cmd_ret;
 
 	cmd->cancel = TRUE;
@@ -76,7 +77,7 @@ void client_command_cancel(struct client
 		if (cmd->client->output->closed)
 			i_panic("command didn't cancel itself: %s", cmd->name);
 	} else {
-		client_command_free(cmd);
+		client_command_free(_cmd);
 	}
 }
 
@@ -112,6 +113,7 @@ static const char *client_get_disconnect
 
 void client_destroy(struct client *client, const char *reason)
 {
+	struct client_command_context *cmd;
 	i_assert(!client->destroyed);
 	client->destroyed = TRUE;
 
@@ -127,11 +129,13 @@ void client_destroy(struct client *clien
 
 	/* finish off all the queued commands. */
 	if (client->output_lock != NULL)
-		client_command_cancel(client->output_lock);
+		client_command_cancel(&client->output_lock);
 	if (client->input_lock != NULL)
-		client_command_cancel(client->input_lock);
-	while (client->command_queue != NULL)
-		client_command_cancel(client->command_queue);
+		client_command_cancel(&client->input_lock);
+	while (client->command_queue != NULL) {
+		cmd = client->command_queue;
+		client_command_cancel(&cmd);
+	}
 
 	if (client->mailbox != NULL)
 		mailbox_close(&client->mailbox);
@@ -398,9 +402,12 @@ client_command_new(struct client *client
 	return cmd;
 }
 
-void client_command_free(struct client_command_context *cmd)
-{
+void client_command_free(struct client_command_context **_cmd)
+{
+	struct client_command_context *cmd = *_cmd;
 	struct client *client = cmd->client;
+
+	*_cmd = NULL;
 
 	/* reset input idle time because command output might have taken a
 	   long time and we don't want to disconnect client immediately then */
@@ -545,7 +552,7 @@ static bool client_command_input(struct 
 		/* command is being executed - continue it */
 		if (cmd->func(cmd) || cmd->state == CLIENT_COMMAND_STATE_DONE) {
 			/* command execution was finished */
-			client_command_free(cmd);
+			client_command_free(&cmd);
 			client_add_missing_io(client);
 			return TRUE;
 		}
@@ -587,7 +594,7 @@ static bool client_command_input(struct 
 		/* unknown command */
 		client_send_command_error(cmd, "Unknown command.");
 		cmd->param_error = TRUE;
-		client_command_free(cmd);
+		client_command_free(&cmd);
 		return TRUE;
 	} else {
 		i_assert(!client->disconnected);
@@ -698,7 +705,7 @@ void client_input(struct client *client)
 			client_command_new(client);
 		cmd->param_error = TRUE;
 		client_send_command_error(cmd, "Too long argument.");
-		client_command_free(cmd);
+		client_command_free(&cmd);
 	}
 	o_stream_uncork(output);
 	o_stream_unref(&output);
@@ -715,7 +722,7 @@ static void client_output_cmd(struct cli
 		(void)client_handle_unfinished_cmd(cmd);
 	else {
 		/* command execution was finished */
-		client_command_free(cmd);
+		client_command_free(&cmd);
 	}
 }
 
diff -r 2b89ceb0f6af -r 33d8adcc2d44 src/imap/client.h
--- a/src/imap/client.h	Thu Mar 20 15:42:57 2008 +0200
+++ b/src/imap/client.h	Thu Mar 20 16:26:27 2008 +0200
@@ -127,8 +127,8 @@ void clients_init(void);
 void clients_init(void);
 void clients_deinit(void);
 
-void client_command_cancel(struct client_command_context *cmd);
-void client_command_free(struct client_command_context *cmd);
+void client_command_cancel(struct client_command_context **cmd);
+void client_command_free(struct client_command_context **cmd);
 
 bool client_handle_unfinished_cmd(struct client_command_context *cmd);
 void client_continue_pending_input(struct client **_client);
diff -r 2b89ceb0f6af -r 33d8adcc2d44 src/imap/cmd-append.c
--- a/src/imap/cmd-append.c	Thu Mar 20 15:42:57 2008 +0200
+++ b/src/imap/cmd-append.c	Thu Mar 20 16:26:27 2008 +0200
@@ -51,7 +51,7 @@ static void client_input_append(struct c
 		cmd_append_finish(cmd->context);
 		/* Reset command so that client_destroy() doesn't try to call
 		   cmd_append_continue_message() anymore. */
-		client_command_free(cmd);
+		client_command_free(&cmd);
 		client_destroy(client, "Disconnected in APPEND");
 		return;
 	case -2:
@@ -69,7 +69,7 @@ static void client_input_append(struct c
 
 		client_send_command_error(cmd, "Too long argument.");
 		cmd->param_error = TRUE;
-		client_command_free(cmd);
+		client_command_free(&cmd);
 		return;
 	}
 
@@ -79,7 +79,7 @@ static void client_input_append(struct c
 	if (!finished && cmd->state != CLIENT_COMMAND_STATE_DONE)
 		(void)client_handle_unfinished_cmd(cmd);
 	else
-		client_command_free(cmd);
+		client_command_free(&cmd);
 	(void)cmd_sync_delayed(client);
 	client_continue_pending_input(&client);
 }
diff -r 2b89ceb0f6af -r 33d8adcc2d44 src/imap/cmd-idle.c
--- a/src/imap/cmd-idle.c	Thu Mar 20 15:42:57 2008 +0200
+++ b/src/imap/cmd-idle.c	Thu Mar 20 16:26:27 2008 +0200
@@ -54,7 +54,7 @@ idle_finish(struct cmd_idle_context *ctx
 
 	o_stream_uncork(client->output);
 	if (free_cmd)
-		client_command_free(ctx->cmd);
+		client_command_free(&ctx->cmd);
 }
 
 static void idle_client_input(struct cmd_idle_context *ctx)
diff -r 2b89ceb0f6af -r 33d8adcc2d44 src/imap/cmd-search.c
--- a/src/imap/cmd-search.c	Thu Mar 20 15:42:57 2008 +0200
+++ b/src/imap/cmd-search.c	Thu Mar 20 16:26:27 2008 +0200
@@ -135,7 +135,7 @@ static void cmd_search_more_callback(str
 	if (!finished)
 		(void)client_handle_unfinished_cmd(cmd);
 	else
-		client_command_free(cmd);
+		client_command_free(&cmd);
 	(void)cmd_sync_delayed(client);
 	client_continue_pending_input(&client);
 }
diff -r 2b89ceb0f6af -r 33d8adcc2d44 src/imap/cmd-x-cancel.c
--- a/src/imap/cmd-x-cancel.c	Thu Mar 20 15:42:57 2008 +0200
+++ b/src/imap/cmd-x-cancel.c	Thu Mar 20 16:26:27 2008 +0200
@@ -16,7 +16,7 @@ bool cmd_x_cancel(struct client_command_
 	for (; cancel_cmd != NULL; cancel_cmd = cancel_cmd->next) {
 		if (cancel_cmd->tag != NULL && cancel_cmd != cmd &&
 		    strcmp(cancel_cmd->tag, tag) == 0) {
-			client_command_cancel(cancel_cmd);
+			client_command_cancel(&cancel_cmd);
 			client_send_tagline(cmd, "OK Command cancelled.");
 			return TRUE;
 		}
diff -r 2b89ceb0f6af -r 33d8adcc2d44 src/imap/imap-sync.c
--- a/src/imap/imap-sync.c	Thu Mar 20 15:42:57 2008 +0200
+++ b/src/imap/imap-sync.c	Thu Mar 20 16:26:27 2008 +0200
@@ -235,7 +235,7 @@ static bool cmd_sync_continue(struct cli
 		    cmd != sync_cmd &&
 		    cmd->sync->counter+1 == client->sync_counter) {
 			if (cmd_finish_sync(cmd))
-				client_command_free(cmd);
+				client_command_free(&cmd);
 		}
 	}
 	return cmd_finish_sync(sync_cmd);
@@ -306,7 +306,7 @@ static bool cmd_sync_client(struct clien
 		return FALSE;
 	}
 
-	client_command_free(sync_cmd);
+	client_command_free(&sync_cmd);
 	(void)cmd_sync_delayed(client);
 	return TRUE;
 }
@@ -372,7 +372,7 @@ static bool cmd_sync_drop_fast(struct cl
 		if (cmd->state == CLIENT_COMMAND_STATE_WAIT_SYNC &&
 		    (cmd->sync->flags & MAILBOX_SYNC_FLAG_FAST) != 0) {
 			if (cmd_finish_sync(cmd)) {
-				client_command_free(cmd);
+				client_command_free(&cmd);
 				ret = TRUE;
 			}
 		}


More information about the dovecot-cvs mailing list