From: Timo Sirainen Date: Sun, 10 Dec 2017 18:00:21 +0000 (+0200) Subject: lib-test: istream-test - Don't modify existing snapshots' memareas X-Git-Tag: 2.3.0.rc1~155 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=21138be4989503314641025ab07a7010a380a159;p=thirdparty%2Fdovecot%2Fcore.git lib-test: istream-test - Don't modify existing snapshots' memareas At least with --enable-devel-checks this caused istream-sized unit test to randomly panic: Panic: file istream.c: line 279 (i_stream_read): assertion failed: (memcmp(prev_buf, prev_data + prev_skip, prev_pos - prev_skip) == 0) --- diff --git a/src/lib-test/test-istream.c b/src/lib-test/test-istream.c index 84f06b1b65..1c3efcf58a 100644 --- a/src/lib-test/test-istream.c +++ b/src/lib-test/test-istream.c @@ -52,9 +52,15 @@ static ssize_t test_read(struct istream_private *stream) cur_max > stream->skip + stream->max_buffer_size) cur_max = stream->skip + stream->max_buffer_size; - /* use exactly correct buffer size so valgrind can catch - read overflows */ - if (stream->buffer_size != cur_max && cur_max > 0) { + /* Reallocate the memory area if needed. Use exactly correct + buffer size so valgrind can catch read overflows. If a + correctly sized memarea already exists, use it only if + its refcount is 1. Otherwise with refcount>1 we could be + moving data within an existing memarea, which breaks + snapshots. */ + if (cur_max > 0 && (stream->buffer_size != cur_max || + stream->memarea == NULL || + memarea_get_refcount(stream->memarea) > 1)) { void *old_w_buffer = stream->w_buffer; stream->w_buffer = i_malloc(cur_max); memcpy(stream->w_buffer, old_w_buffer,