diff --git a/modules/database/src/ioc/rsrv/caservertask.c b/modules/database/src/ioc/rsrv/caservertask.c index 7a9ae63b3..ea6fb3262 100644 --- a/modules/database/src/ioc/rsrv/caservertask.c +++ b/modules/database/src/ioc/rsrv/caservertask.c @@ -1343,8 +1343,15 @@ void casExpandBuffer ( struct message_buffer *buf, ca_uint32_t size, int sendbuf // round up to multiple of 4K size = ((size-1)|0xfff)+1; - if (buf->type==mbtLargeTCP) + if (buf->type==mbtLargeTCP) { newbuf = realloc (buf->buf, size); + /* + * realloc() copied the data and invalidated the old buffer! + * So if we need to copy data from the old buffer, it's now at + * the same position in the new buffer. + */ + buf->buf = newbuf; + } else newbuf = malloc (size); newtype = mbtLargeTCP;