From: Michael Paquier <michael@paquier.xyz>
To: Andres Freund <andres@anarazel.de>
Cc: Tom Lane <tgl@sss.pgh.pa.us>
Cc: Euler Taveira <euler@eulerto.com>
Cc: ranier.vf@gmail.com <ranier.vf@gmail.com>
Cc: pgsql-hackers <pgsql-hackers@postgresql.org>
Subject: Re: Small memory fixes for pg_createsubcriber
Date: Thu, 13 Feb 2025 08:56:53 +0900
Message-ID: <Z601RQxTmIUohdkV@paquier.xyz> (raw)
In-Reply-To: <xseczrku4nm3p4rujapxiiuttpqrpagkbwrr2nlbnmwemh525y@3he54emhpqha>
References: <CAEudQAp=AW5dJXrGLbC_aZg_9nOo=42W7uLDRONFQE-gcgnkgQ@mail.gmail.com>
<68d6d810-4ef1-4f62-b47f-89b21501249b@app.fastmail.com>
<obqvpv4yx57lbnfiqvy4pmnfi2l5wn6xzoq2ftytxa426pa226@2sc46frt5xtb>
<3337507.1739376124@sss.pgh.pa.us>
<xseczrku4nm3p4rujapxiiuttpqrpagkbwrr2nlbnmwemh525y@3he54emhpqha>
On Wed, Feb 12, 2025 at 12:00:03PM -0500, Andres Freund wrote:
> Particularly for something like libpq it's not quitetrivial to add
> attributes like this, of course. We can't even depend on pg_config.h.
>
> One way would be to define them in libpq-fe.h, guarded by an #ifdef, that's
> "armed" by a commandline -D flag, if the compiler is supported?
Interesting set of tricks.
I have looked at bit at the uses of PQescapeLiteral() and
PQescapeIdentifier() in the tree. On top of the one in pg_amcheck you
are just pointing to, there is an inconsistency in pg_upgrade.c for
set_locale_and_encoding() where datlocale_literal may be allocated
with a pg_strdup() or a PQescapeLiteral() depending on the path. The
code has been using PQfreemem() for the pg_strdup() allocation, which
is logically incorrect.
The pg_upgrade path is fancy as designed this way, for sure, but
that's less invasive than hardcoding three times "NULL". Any thoughts
about backpatching something like that for both of them?
--
Michael
Attachments:libpq-escape-fixes.patch (text/x-diff, 846B) downloaddiff --git a/src/bin/pg_amcheck/pg_amcheck.c b/src/bin/pg_amcheck/pg_amcheck.cindex c5ec25be22b..dda8b1b8ade 100644--- a/src/bin/pg_amcheck/pg_amcheck.c+++ b/src/bin/pg_amcheck/pg_amcheck.c@@ -560,7 +560,7 @@ main(int argc, char *argv[])
executeCommand(conn, install_sql, opts.echo);
pfree(install_sql);
- pfree(schema);+ PQfreemem(schema);
}
/*
diff --git a/src/bin/pg_upgrade/pg_upgrade.c b/src/bin/pg_upgrade/pg_upgrade.cindex 36c7f3879d5..d854ad110ee 100644--- a/src/bin/pg_upgrade/pg_upgrade.c+++ b/src/bin/pg_upgrade/pg_upgrade.c@@ -465,7 +465,10 @@ set_locale_and_encoding(void)
PQfreemem(datcollate_literal);
PQfreemem(datctype_literal);
- PQfreemem(datlocale_literal);+ if (locale->db_locale)+ PQfreemem(datlocale_literal);+ else+ pg_free(datlocale_literal);
PQfinish(conn_new_template1);
signature.asc (application/pgp-signature, 832B) download
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-hackers@postgresql.org
Cc: michael@paquier.xyz, andres@anarazel.de, tgl@sss.pgh.pa.us, euler@eulerto.com, ranier.vf@gmail.com
Subject: Re: Small memory fixes for pg_createsubcriber
In-Reply-To: <Z601RQxTmIUohdkV@paquier.xyz>
* 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