dovecot-2.2: Memory leak fixes

dovecot at dovecot.org dovecot at dovecot.org
Mon Aug 13 07:28:48 EEST 2012


details:   http://hg.dovecot.org/dovecot-2.2/rev/0e4be366edb4
changeset: 14892:0e4be366edb4
user:      Timo Sirainen <tss at iki.fi>
date:      Mon Aug 13 07:28:40 2012 +0300
description:
Memory leak fixes

diffstat:

 src/imap/imap-fetch-body.c |  28 +++++++++++++++++++++-------
 src/imap/imap-fetch.c      |  29 ++++++++++++++---------------
 2 files changed, 35 insertions(+), 22 deletions(-)

diffs (118 lines):

diff -r 7bda77ccd1fc -r 0e4be366edb4 src/imap/imap-fetch-body.c
--- a/src/imap/imap-fetch-body.c	Mon Aug 13 05:45:35 2012 +0300
+++ b/src/imap/imap-fetch-body.c	Mon Aug 13 07:28:40 2012 +0300
@@ -126,11 +126,16 @@
 }
 
 static int fetch_body_msgpart(struct imap_fetch_context *ctx, struct mail *mail,
-			      const struct imap_fetch_body_data *body)
+			      struct imap_fetch_body_data *body)
 {
 	struct imap_msgpart_open_result result;
 	string_t *str;
 
+	if (mail == NULL) {
+		imap_msgpart_free(&body->msgpart);
+		return 1;
+	}
+
 	if (imap_msgpart_open(mail, body->msgpart, &result) < 0)
 		return -1;
 	ctx->state.cur_input = result.input;
@@ -147,11 +152,16 @@
 }
 
 static int fetch_binary_size(struct imap_fetch_context *ctx, struct mail *mail,
-			     const struct imap_fetch_body_data *body)
+			     struct imap_fetch_body_data *body)
 {
 	string_t *str;
 	size_t size;
 
+	if (mail == NULL) {
+		imap_msgpart_free(&body->msgpart);
+		return 1;
+	}
+
 	if (imap_msgpart_size(mail, body->msgpart, &size) < 0)
 		return -1;
 
@@ -325,7 +335,8 @@
 
 	/* update the section name for the imap_fetch_add_handler() */
 	ctx->name = p_strdup(ctx->pool, get_body_name(body));
-	imap_fetch_add_handler(ctx, 0, "NIL", fetch_body_msgpart, body);
+	imap_fetch_add_handler(ctx, IMAP_FETCH_HANDLER_FLAG_WANT_DEINIT,
+			       "NIL", fetch_body_msgpart, body);
 	return TRUE;
 }
 
@@ -397,10 +408,13 @@
 
 	/* update the section name for the imap_fetch_add_handler() */
 	ctx->name = p_strdup(ctx->pool, get_body_name(body));
-	if (body->binary_size)
-		imap_fetch_add_handler(ctx, 0, "NIL", fetch_binary_size, body);
-	else
-		imap_fetch_add_handler(ctx, 0, "NIL", fetch_body_msgpart, body);
+	if (body->binary_size) {
+		imap_fetch_add_handler(ctx, IMAP_FETCH_HANDLER_FLAG_WANT_DEINIT,
+				       "NIL", fetch_binary_size, body);
+	} else {
+		imap_fetch_add_handler(ctx, IMAP_FETCH_HANDLER_FLAG_WANT_DEINIT,
+				       "NIL", fetch_body_msgpart, body);
+	}
 	return TRUE;
 }
 
diff -r 7bda77ccd1fc -r 0e4be366edb4 src/imap/imap-fetch.c
--- a/src/imap/imap-fetch.c	Mon Aug 13 05:45:35 2012 +0300
+++ b/src/imap/imap-fetch.c	Mon Aug 13 07:28:40 2012 +0300
@@ -573,22 +573,15 @@
 int imap_fetch_end(struct imap_fetch_context *ctx)
 {
 	struct imap_fetch_state *state = &ctx->state;
-	const struct imap_fetch_context_handler *handler;
 
-	if (!ctx->state.fetching)
-		return 0;
-	ctx->state.fetching = FALSE;
-
-	array_foreach(&ctx->handlers, handler) {
-		if (handler->want_deinit)
-			handler->handler(ctx, NULL, handler->context);
-	}
-
-	if (!state->line_finished) {
-		if (imap_fetch_flush_buffer(ctx) < 0)
-			state->failed = TRUE;
-		if (o_stream_send(ctx->client->output, ")\r\n", 3) < 0)
-			state->failed = TRUE;
+	if (ctx->state.fetching) {
+		ctx->state.fetching = FALSE;
+		if (!state->line_finished) {
+			if (imap_fetch_flush_buffer(ctx) < 0)
+				state->failed = TRUE;
+			if (o_stream_send(ctx->client->output, ")\r\n", 3) < 0)
+				state->failed = TRUE;
+		}
 	}
 	if (state->cur_str != NULL)
 		str_free(&state->cur_str);
@@ -614,10 +607,16 @@
 void imap_fetch_free(struct imap_fetch_context **_ctx)
 {
 	struct imap_fetch_context *ctx = *_ctx;
+	const struct imap_fetch_context_handler *handler;
 
 	*_ctx = NULL;
 
 	(void)imap_fetch_end(ctx);
+
+	array_foreach(&ctx->handlers, handler) {
+		if (handler->want_deinit)
+			handler->handler(ctx, NULL, handler->context);
+	}
 	if (ctx->search_args != NULL)
 		mail_search_args_unref(&ctx->search_args);
 	pool_unref(&ctx->ctx_pool);


More information about the dovecot-cvs mailing list