]> git.kaiwu.me - nginx.git/commit
Perl: fixed $r->print() zero copy with mutable scalars
authorDavid Carlier <devnexen@gmail.com>
Tue, 21 Jul 2026 03:35:57 +0000 (04:35 +0100)
committerVadimZhestikov <108960056+VadimZhestikov@users.noreply.github.com>
Fri, 24 Jul 2026 15:42:30 +0000 (08:42 -0700)
commit5e0deb7018b06cdebafab5570b2e9fdf7c3f22de
tree3d3a2a1fc14db2bb7d541c5a63af0d9df42465ba
parenteaac3d771b21adf4e3ca6cd79bdb398f973a1047
Perl: fixed $r->print() zero copy with mutable scalars

Since d9b7669666c8, the single-SV zero copy path in $r->print() no
longer required the SV to be read-only.  Reference counting introduced
by that change keeps the SV alive, but not its string buffer: modifying
a mutable scalar after $r->print() overwrites the buffer in place or
reallocates it, while nginx might still have it queued in r->out, since
small responses are postponed by ngx_http_write_filter().  This resulted
in corrupted responses, and in freed memory being sent to the client
when the scalar was grown.

The SV is now required to be read-only again.  Reference counting is
still needed here, as a read-only SV in an eval() might be freed with
the eval's op tree.
src/http/modules/perl/nginx.xs