pgsql: Clean up impenetrable logic in pg_basebackup/receivelog.c.

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: Clean up impenetrable logic in pg_basebackup/receivelog.c.
Date: 2025-02-12 21:07:50
Message-ID: E1tiJxW-006nUC-9u@gemulon.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-committers

Clean up impenetrable logic in pg_basebackup/receivelog.c.

Coverity complained about possible double free of HandleCopyStream's
"copybuf". AFAICS it's mistaken, but it is easy to see why it's
confused, because management of that buffer is impossibly confusing.
It's unreasonable that HandleEndOfCopyStream frees the buffer in some
cases but not others, updates the caller's state for that in no case,
and has not a single comment about how complicated that makes things.

Let's put all the responsibility for freeing copybuf in the actual
owner of that variable, HandleCopyStream. This results in one more
PQfreemem call than before, but the logic is far easier to follow,
both for humans and machines.

Since this isn't (quite) actually broken, no back-patch.

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/fd602f29c19d4f483f54d93abe240c12219d9f51

Modified Files
--------------
src/bin/pg_basebackup/receivelog.c | 21 ++++++++++++++-------
1 file changed, 14 insertions(+), 7 deletions(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Nathan Bossart 2025-02-12 21:46:40 pgsql: Remove unneeded volatile qualifier in fmgr.c.
Previous Message Andres Freund 2025-02-12 14:40:40 pgsql: ci: Test NetBSD and OpenBSD