]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-storage: Small code cleanup for index_mail_get_binary_stream()
authorTimo Sirainen <tss@iki.fi>
Thu, 23 Apr 2015 10:27:17 +0000 (13:27 +0300)
committerTimo Sirainen <tss@iki.fi>
Thu, 23 Apr 2015 10:27:17 +0000 (13:27 +0300)
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.

src/lib-storage/index/index-mail-binary.c

index 5be0e02666adb9c251ac951e9d49a91073ead9b6..f89f6db85ca0d0aab80918c8752c2215d4af66c3 100644 (file)
@@ -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;
 }