dovecot-2.2: cydir, dbox, maildir: Don't leak the stream if mail...

dovecot at dovecot.org dovecot at dovecot.org
Tue Feb 5 03:24:58 EET 2013


details:   http://hg.dovecot.org/dovecot-2.2/rev/1a6cf87eeff0
changeset: 15738:1a6cf87eeff0
user:      Timo Sirainen <tss at iki.fi>
date:      Tue Feb 05 03:24:45 2013 +0200
description:
cydir, dbox, maildir: Don't leak the stream if mail.istream_opened() fails

diffstat:

 src/lib-storage/index/cydir/cydir-mail.c      |  12 ++++++++----
 src/lib-storage/index/dbox-common/dbox-mail.c |   6 +++++-
 src/lib-storage/index/maildir/maildir-mail.c  |   4 +++-
 3 files changed, 16 insertions(+), 6 deletions(-)

diffs (71 lines):

diff -r be320a216190 -r 1a6cf87eeff0 src/lib-storage/index/cydir/cydir-mail.c
--- a/src/lib-storage/index/cydir/cydir-mail.c	Tue Feb 05 03:23:59 2013 +0200
+++ b/src/lib-storage/index/cydir/cydir-mail.c	Tue Feb 05 03:24:45 2013 +0200
@@ -98,6 +98,7 @@
 		      struct istream **stream_r)
 {
 	struct index_mail *mail = (struct index_mail *)_mail;
+	struct istream *input;
 	const char *path;
 	int fd;
 
@@ -114,13 +115,16 @@
 			}
 			return -1;
 		}
-		mail->data.stream = i_stream_create_fd(fd, 0, TRUE);
-		i_stream_set_name(mail->data.stream, path);
-		index_mail_set_read_buffer_size(_mail, mail->data.stream);
+		input = i_stream_create_fd(fd, 0, TRUE);
+		i_stream_set_name(input, path);
+		index_mail_set_read_buffer_size(_mail, input);
 		if (mail->mail.v.istream_opened != NULL) {
-			if (mail->mail.v.istream_opened(_mail, stream_r) < 0)
+			if (mail->mail.v.istream_opened(_mail, &input) < 0) {
+				i_stream_unref(&input);
 				return -1;
+			}
 		}
+		mail->data.stream = input;
 	}
 
 	return index_mail_init_stream(mail, hdr_size, body_size, stream_r);
diff -r be320a216190 -r 1a6cf87eeff0 src/lib-storage/index/dbox-common/dbox-mail.c
--- a/src/lib-storage/index/dbox-common/dbox-mail.c	Tue Feb 05 03:23:59 2013 +0200
+++ b/src/lib-storage/index/dbox-common/dbox-mail.c	Tue Feb 05 03:24:45 2013 +0200
@@ -220,8 +220,10 @@
 	struct dbox_file *file = mail->open_file;
 	int ret;
 
-	if ((ret = dbox_file_seek(file, offset)) <= 0)
+	if ((ret = dbox_file_seek(file, offset)) <= 0) {
+		*stream_r = NULL;
 		return ret;
+	}
 
 	*stream_r = i_stream_create_limit(file->input, file->cur_physical_size);
 	if (pmail->v.istream_opened != NULL) {
@@ -258,6 +260,8 @@
 			dbox_file_set_corrupted(mail->open_file,
 				"uid=%u points to broken data at offset="
 				"%"PRIuUOFF_T, _mail->uid, offset);
+			if (input != NULL)
+				i_stream_unref(&input);
 			return -1;
 		}
 		data->stream = input;
diff -r be320a216190 -r 1a6cf87eeff0 src/lib-storage/index/maildir/maildir-mail.c
--- a/src/lib-storage/index/maildir/maildir-mail.c	Tue Feb 05 03:23:59 2013 +0200
+++ b/src/lib-storage/index/maildir/maildir-mail.c	Tue Feb 05 03:24:45 2013 +0200
@@ -584,8 +584,10 @@
 		}
 		if (mail->mail.v.istream_opened != NULL) {
 			if (mail->mail.v.istream_opened(_mail,
-							&data->stream) < 0)
+							&data->stream) < 0) {
+				i_stream_unref(&data->stream);
 				return -1;
+			}
 		}
 	}
 


More information about the dovecot-cvs mailing list