Mercurial > dovecot > original-hg > dovecot-1.2
changeset 4073:cd701884900c HEAD
Memory leak fixes
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Sun, 26 Feb 2006 13:24:35 +0200 |
parents | 7e6acdd8d18d |
children | dadc6e2cccb8 |
files | src/imap/imap-fetch-body.c src/imap/imap-fetch.c src/imap/imap-fetch.h src/lib-storage/index/index-mail.c src/lib-storage/index/index-storage.c src/lib-storage/index/index-sync.c src/lib-storage/index/maildir/maildir-keywords.c |
diffstat | 7 files changed, 54 insertions(+), 23 deletions(-) [+] |
line wrap: on
line diff
--- a/src/imap/imap-fetch-body.c Sun Feb 26 12:32:19 2006 +0200 +++ b/src/imap/imap-fetch-body.c Sun Feb 26 13:24:35 2006 +0200 @@ -409,10 +409,16 @@ static int fetch_body_header_fields(struct imap_fetch_context *ctx, struct mail *mail, void *context) { - const struct imap_fetch_body_data *body = context; + struct imap_fetch_body_data *body = context; struct message_size size; uoff_t old_offset; + if (mail == NULL) { + /* deinit */ + mailbox_header_lookup_deinit(&body->header_ctx); + return 0; + } + ctx->cur_input = mail_get_header_stream(mail, body->header_ctx); if (ctx->cur_input == NULL) return -1; @@ -590,7 +596,7 @@ MAIL_FETCH_STREAM_BODY)) != 0) { /* we'll need to open the file anyway, don't try to get the headers from cache. */ - imap_fetch_add_handler(ctx, FALSE, + imap_fetch_add_handler(ctx, FALSE, FALSE, fetch_body_header_partial, body); return TRUE; } @@ -603,7 +609,8 @@ } body->header_ctx = mailbox_header_lookup_init(ctx->box, body->fields); - imap_fetch_add_handler(ctx, FALSE, fetch_body_header_fields, body); + imap_fetch_add_handler(ctx, FALSE, TRUE, + fetch_body_header_fields, body); t_pop(); return TRUE; } @@ -616,13 +623,13 @@ if (*section == '\0') { ctx->fetch_data |= MAIL_FETCH_STREAM_HEADER | MAIL_FETCH_STREAM_BODY; - imap_fetch_add_handler(ctx, FALSE, fetch_body, body); + imap_fetch_add_handler(ctx, FALSE, FALSE, fetch_body, body); return TRUE; } if (strcmp(section, "TEXT") == 0) { ctx->fetch_data |= MAIL_FETCH_STREAM_BODY; - imap_fetch_add_handler(ctx, FALSE, fetch_body, body); + imap_fetch_add_handler(ctx, FALSE, FALSE, fetch_body, body); return TRUE; } @@ -630,7 +637,8 @@ /* exact header matches could be cached */ if (section[6] == '\0') { ctx->fetch_data |= MAIL_FETCH_STREAM_HEADER; - imap_fetch_add_handler(ctx, FALSE, fetch_body, body); + imap_fetch_add_handler(ctx, FALSE, FALSE, + fetch_body, body); return TRUE; } @@ -640,7 +648,7 @@ if (strncmp(section, "HEADER.FIELDS.NOT ", 18) == 0 && fetch_body_header_fields_check(section+18)) { - imap_fetch_add_handler(ctx, FALSE, + imap_fetch_add_handler(ctx, FALSE, FALSE, fetch_body_header_partial, body); return TRUE; } @@ -659,7 +667,7 @@ fetch_body_header_fields_check(section+14)) || (strncmp(section, "HEADER.FIELDS.NOT ", 18) == 0 && fetch_body_header_fields_check(section+18))) { - imap_fetch_add_handler(ctx, FALSE, + imap_fetch_add_handler(ctx, FALSE, FALSE, fetch_body_mime, body); return TRUE; } @@ -923,24 +931,27 @@ ctx->fetch_data |= MAIL_FETCH_STREAM_HEADER | MAIL_FETCH_STREAM_BODY; ctx->flags_update_seen = TRUE; - imap_fetch_add_handler(ctx, FALSE, fetch_rfc822, NULL); + imap_fetch_add_handler(ctx, FALSE, FALSE, fetch_rfc822, NULL); return TRUE; } if (strcmp(name+6, ".SIZE") == 0) { ctx->fetch_data |= MAIL_FETCH_VIRTUAL_SIZE; - imap_fetch_add_handler(ctx, TRUE, fetch_rfc822_size, NULL); + imap_fetch_add_handler(ctx, TRUE, FALSE, + fetch_rfc822_size, NULL); return TRUE; } if (strcmp(name+6, ".HEADER") == 0) { ctx->fetch_data |= MAIL_FETCH_STREAM_HEADER; - imap_fetch_add_handler(ctx, FALSE, fetch_rfc822_header, NULL); + imap_fetch_add_handler(ctx, FALSE, FALSE, + fetch_rfc822_header, NULL); return TRUE; } if (strcmp(name+6, ".TEXT") == 0) { ctx->fetch_data |= MAIL_FETCH_STREAM_BODY; ctx->flags_update_seen = TRUE; - imap_fetch_add_handler(ctx, FALSE, fetch_rfc822_text, NULL); + imap_fetch_add_handler(ctx, FALSE, FALSE, + fetch_rfc822_text, NULL); return TRUE; }
--- a/src/imap/imap-fetch.c Sun Feb 26 12:32:19 2006 +0200 +++ b/src/imap/imap-fetch.c Sun Feb 26 13:24:35 2006 +0200 @@ -100,7 +100,8 @@ return ctx; } -void imap_fetch_add_handler(struct imap_fetch_context *ctx, bool buffered, +void imap_fetch_add_handler(struct imap_fetch_context *ctx, + bool buffered, bool want_deinit, imap_fetch_handler_t *handler, void *context) { /* partially because of broken clients, but also partially because @@ -132,6 +133,7 @@ h.handler = handler; h.context = context; h.buffered = buffered; + h.want_deinit = want_deinit; if (!buffered) array_append(&ctx->handlers, &h, 1); @@ -302,6 +304,15 @@ int imap_fetch_deinit(struct imap_fetch_context *ctx) { + const struct imap_fetch_context_handler *handlers; + unsigned int i, count; + + handlers = array_get(&ctx->handlers, &count); + for (i = 0; i < count; i++) { + if (handlers[i].want_deinit) + handlers[i].handler(ctx, NULL, handlers[i].context); + } + str_free(&ctx->cur_str); if (!ctx->line_finished) { @@ -361,7 +372,7 @@ { if (name[4] == '\0') { ctx->fetch_data |= MAIL_FETCH_IMAP_BODY; - imap_fetch_add_handler(ctx, FALSE, fetch_body, NULL); + imap_fetch_add_handler(ctx, FALSE, FALSE, fetch_body, NULL); return TRUE; } return fetch_body_section_init(ctx, name, args); @@ -396,7 +407,7 @@ struct imap_arg **args __attr_unused__) { ctx->fetch_data |= MAIL_FETCH_IMAP_BODYSTRUCTURE; - imap_fetch_add_handler(ctx, FALSE, fetch_bodystructure, NULL); + imap_fetch_add_handler(ctx, FALSE, FALSE, fetch_bodystructure, NULL); return TRUE; } @@ -428,7 +439,7 @@ struct imap_arg **args __attr_unused__) { ctx->fetch_data |= MAIL_FETCH_IMAP_ENVELOPE; - imap_fetch_add_handler(ctx, FALSE, fetch_envelope, NULL); + imap_fetch_add_handler(ctx, FALSE, FALSE, fetch_envelope, NULL); return TRUE; } @@ -462,7 +473,7 @@ { ctx->flags_have_handler = TRUE; ctx->fetch_data |= MAIL_FETCH_FLAGS; - imap_fetch_add_handler(ctx, TRUE, fetch_flags, NULL); + imap_fetch_add_handler(ctx, TRUE, FALSE, fetch_flags, NULL); return TRUE; } @@ -486,7 +497,7 @@ struct imap_arg **args __attr_unused__) { ctx->fetch_data |= MAIL_FETCH_RECEIVED_DATE; - imap_fetch_add_handler(ctx, TRUE, fetch_internaldate, NULL); + imap_fetch_add_handler(ctx, TRUE, FALSE, fetch_internaldate, NULL); return TRUE; } @@ -501,7 +512,7 @@ const char *name __attr_unused__, struct imap_arg **args __attr_unused__) { - imap_fetch_add_handler(ctx, TRUE, fetch_uid, NULL); + imap_fetch_add_handler(ctx, TRUE, FALSE, fetch_uid, NULL); return TRUE; }
--- a/src/imap/imap-fetch.h Sun Feb 26 12:32:19 2006 +0200 +++ b/src/imap/imap-fetch.h Sun Feb 26 13:24:35 2006 +0200 @@ -19,7 +19,9 @@ struct imap_fetch_context_handler { imap_fetch_handler_t *handler; void *context; - bool buffered; + + unsigned int buffered:1; + unsigned int want_deinit:1; }; struct imap_fetch_context { @@ -63,7 +65,8 @@ void imap_fetch_handlers_register(const struct imap_fetch_handler *handlers, size_t count); -void imap_fetch_add_handler(struct imap_fetch_context *ctx, bool buffered, +void imap_fetch_add_handler(struct imap_fetch_context *ctx, + bool buffered, bool want_deinit, imap_fetch_handler_t *handler, void *context); struct imap_fetch_context *imap_fetch_init(struct client_command_context *cmd);
--- a/src/lib-storage/index/index-mail.c Sun Feb 26 12:32:19 2006 +0200 +++ b/src/lib-storage/index/index-mail.c Sun Feb 26 13:24:35 2006 +0200 @@ -387,7 +387,6 @@ message_parser_parse_body(data->parser_ctx, NULL, NULL, NULL); } data->parts = message_parser_deinit(&data->parser_ctx); - data->parser_ctx = NULL; if (data->parsed_bodystructure && imap_bodystructure_is_plain_7bit(data->parts)) { @@ -747,6 +746,8 @@ static void index_mail_close(struct index_mail *mail) { + if (mail->data.parser_ctx != NULL) + (void)message_parser_deinit(&mail->data.parser_ctx); if (mail->data.stream != NULL) i_stream_destroy(&mail->data.stream); if (mail->data.filter_stream != NULL)
--- a/src/lib-storage/index/index-storage.c Sun Feb 26 12:32:19 2006 +0200 +++ b/src/lib-storage/index/index-storage.c Sun Feb 26 13:24:35 2006 +0200 @@ -391,7 +391,9 @@ index_mailbox_check_remove_all(ibox); if (ibox->index != NULL) index_storage_unref(ibox->index); - i_free(ibox->cache_fields); + if (ibox->recent_flags != NULL) + buffer_free(ibox->recent_flags); + i_free(ibox->cache_fields); pool_unref(box->pool); }
--- a/src/lib-storage/index/index-sync.c Sun Feb 26 12:32:19 2006 +0200 +++ b/src/lib-storage/index/index-sync.c Sun Feb 26 13:24:35 2006 +0200 @@ -21,6 +21,8 @@ unsigned char *p; size_t dest_idx; + i_assert(seq != 0); + if (ibox->recent_flags_start_seq == 0) { ibox->recent_flags = buffer_create_dynamic(default_pool, 128); ibox->recent_flags_start_seq = seq;