From: Timo Sirainen Date: Thu, 23 Apr 2015 10:27:17 +0000 (+0300) Subject: lib-storage: Small code cleanup for index_mail_get_binary_stream() X-Git-Tag: 2.2.17.rc1~170 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=471eed36d9aee2f7d99072a4fc5e164a6741194b;p=thirdparty%2Fdovecot%2Fcore.git lib-storage: Small code cleanup for index_mail_get_binary_stream() stream_r is always non-NULL here. Also move unreferencing cache istream to be last in case it might fix data.stream=NULL being here in some situations. --- diff --git a/src/lib-storage/index/index-mail-binary.c b/src/lib-storage/index/index-mail-binary.c index 5be0e02666..f89f6db85c 100644 --- a/src/lib-storage/index/index-mail-binary.c +++ b/src/lib-storage/index/index-mail-binary.c @@ -571,23 +571,20 @@ int index_mail_get_binary_stream(struct mail *_mail, } *size_r = cache->size; *binary_r = binary; - if (stream_r != NULL) { - i_stream_ref(cache->input); - *stream_r = cache->input; - } if (!converted) { /* don't keep this cached. it's exactly the same as the original stream */ + i_assert(mail->data.stream != NULL); + i_stream_seek(mail->data.stream, part->physical_pos + + (include_hdr ? 0 : + part->header_size.physical_size)); + input = i_stream_create_crlf(mail->data.stream); + *stream_r = i_stream_create_limit(input, *size_r); + i_stream_unref(&input); mail_storage_free_binary_cache(_mail->box->storage); - if (stream_r != NULL) { - i_stream_unref(stream_r); - i_stream_seek(mail->data.stream, part->physical_pos + - (include_hdr ? 0 : - part->header_size.physical_size)); - input = i_stream_create_crlf(mail->data.stream); - *stream_r = i_stream_create_limit(input, *size_r); - i_stream_unref(&input); - } + } else { + *stream_r = cache->input; + i_stream_ref(cache->input); } return 0; }