[dovecot-cvs] dovecot/src/imap imap-fetch-body.c, 1.27,
1.28 imap-fetch.c, 1.42, 1.43 imap-fetch.h, 1.17, 1.18
cras at dovecot.org
cras at dovecot.org
Sun Feb 26 13:24:37 EET 2006
Update of /var/lib/cvs/dovecot/src/imap
In directory talvi:/tmp/cvs-serv4215/imap
Modified Files:
imap-fetch-body.c imap-fetch.c imap-fetch.h
Log Message:
Memory leak fixes
Index: imap-fetch-body.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/imap/imap-fetch-body.c,v
retrieving revision 1.27
retrieving revision 1.28
diff -u -d -r1.27 -r1.28
--- imap-fetch-body.c 14 Jan 2006 18:47:21 -0000 1.27
+++ imap-fetch-body.c 26 Feb 2006 11:24:35 -0000 1.28
@@ -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;
}
Index: imap-fetch.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/imap/imap-fetch.c,v
retrieving revision 1.42
retrieving revision 1.43
diff -u -d -r1.42 -r1.43
--- imap-fetch.c 14 Jan 2006 18:47:21 -0000 1.42
+++ imap-fetch.c 26 Feb 2006 11:24:35 -0000 1.43
@@ -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;
}
Index: imap-fetch.h
===================================================================
RCS file: /var/lib/cvs/dovecot/src/imap/imap-fetch.h,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -d -r1.17 -r1.18
--- imap-fetch.h 13 Jan 2006 20:25:59 -0000 1.17
+++ imap-fetch.h 26 Feb 2006 11:24:35 -0000 1.18
@@ -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);
More information about the dovecot-cvs
mailing list