logical decoding: Correctly free speculative insertion

The error path in ReorderBufferProcessTXN was not freeing
(reorderbuffer.c's representation of) a speculative insertion record
correctly.  In assert-enabled builds, this leads to an assertion
failure.  In production builds, I see no effect; there may be a small
transient leak, but in an improbable code path such as this, such a leak
is not of any significance.  For users running with assertions enabled,
the crash is annoying.

Fix by having ReorderBufferProcessTXN() free the speculative insert
ahead of freeing the rest of the transaction, and no longer try to
handle that insert as a separate argument to ReorderBufferResetTXN().

This code came in with commit 7259736a6e5b (14-era).  Backpatch all the
way back.

In branches 14-16, also backpatch the assertion that originally fails in
the problem scenario, which was added by dbed2e36625d (originally
backpatched to 17), that at the end of ReorderBufferReturnTXN() the
in-memory size of the transaction is zero.

Author: Vishal Prasanna <[email protected]>
Reviewed-by: Hayato Kuroda <[email protected]>
Backpatch-through: 14
Discussion: 
https://postgr.es/m/[email protected]

Branch
------
REL_15_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/1add4a41bc317b4efa053ad2f2d3347f94864789

Modified Files
--------------
src/backend/replication/logical/reorderbuffer.c | 25 +++++++-------
src/test/subscription/t/100_bugs.pl             | 45 +++++++++++++++++++++++++
2 files changed, 58 insertions(+), 12 deletions(-)

Reply via email to