pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Clean up impenetrable logic in pg_basebackup/receivelog.c.
Date: Wed, 12 Feb 2025 21:07:50 +0000
Message-ID: <E1tiJxW-006nUC-9u@gemulon.postgresql.org> (raw)

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(-)



Message-ID: <E1tiJxW-006nUC-9u@gemulon.postgresql.org>
Permalink:  ../E1tiJxW-006nUC-9u@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1tiJxW-006nUC-9u@gemulon.postgresql.org

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-committers@postgresql.org
  Cc: tgl@sss.pgh.pa.us, pgsql-committers@lists.postgresql.org
  Subject: Re: pgsql: Clean up impenetrable logic in pg_basebackup/receivelog.c.
  In-Reply-To: <E1tiJxW-006nUC-9u@gemulon.postgresql.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox