Mercurial > dovecot > core-2.2
diff src/imap/imap-fetch-body.c @ 14892:0e4be366edb4
Memory leak fixes
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Mon, 13 Aug 2012 07:28:40 +0300 |
parents | 00be97a2139a |
children | 8e29272c35fa |
line wrap: on
line diff
--- 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; }