Skip to content

Commit 1ca63e1

Browse files
xbaselzuiderkwast
authored andcommitted
Bug fix: reset io_last_written on c->buf resize to prevent stale pointers (#2786)
Fixes an assert crash in _writeToClient(): serverAssert(c->io_last_written.data_len == 0 || c->io_last_written.buf == c->buf); The issue occurs when clientsCronResizeOutputBuffer() grows or reallocates c->buf while io_last_written still points to the old buffer and data_len is non-zero. On the next write, both conditions in the assertion become false. Reset io_last_written when resizing the output buffer to prevent stale pointers and keep state consistent. fixes #2769 Signed-off-by: xbasel <[email protected]>
1 parent b828044 commit 1ca63e1

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

src/server.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -988,6 +988,9 @@ int clientsCronResizeOutputBuffer(client *c, mstime_t now_ms) {
988988
size_t oldbuf_size = c->buf_usable_size;
989989
c->buf = zmalloc_usable(new_buffer_size, &c->buf_usable_size);
990990
memcpy(c->buf, oldbuf, c->bufpos);
991+
if (c->io_last_written.buf == oldbuf) {
992+
c->io_last_written.buf = c->buf;
993+
}
991994
zfree_with_size(oldbuf, oldbuf_size);
992995
}
993996
return 0;

0 commit comments

Comments
 (0)