Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1tiMbN-00F3eI-HG for pgsql-hackers@arkaria.postgresql.org; Wed, 12 Feb 2025 23:57:09 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1tiMbL-00GgTp-5D for pgsql-hackers@arkaria.postgresql.org; Wed, 12 Feb 2025 23:57:07 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1tiMbK-00GgPM-RP for pgsql-hackers@lists.postgresql.org; Wed, 12 Feb 2025 23:57:07 +0000 Received: from fout-b3-smtp.messagingengine.com ([202.12.124.146]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1tiMbJ-000U6n-22 for pgsql-hackers@postgresql.org; Wed, 12 Feb 2025 23:57:06 +0000 Received: from phl-compute-06.internal (phl-compute-06.phl.internal [10.202.2.46]) by mailfout.stl.internal (Postfix) with ESMTP id A3483114012C; Wed, 12 Feb 2025 18:57:04 -0500 (EST) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-06.internal (MEProxy); Wed, 12 Feb 2025 18:57:04 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=paquier.xyz; h= cc:cc:content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm3; t=1739404624; x=1739491024; bh=DoyLnYvTZW NvZX7beByUBCgXSzqbcYSTSl6eC9nKhn4=; b=RqAJR80n3dJVHpTFfS4t3dVKYB Udi7mPuk7MznUFGJ256GndGA7bV03g7u3Dbag1qGTuNTwF5mCyKvSkGW3UjUHUVZ TZw0L3eB+in/CIFWKfxQvqM/500SfSwTf5PBD54UjSgfVDhWtH1LxtnDSZqaD6RG nMC8/cFka54rHY1z/Neevt4hIjO7fDOkeIGCCL5LxYyMvRemm3szWUzMV0YAbGFk Xvlv+seEaDq+EnCm2VeI0UYGzKwjDLYMwhrkre1KhOAQzP2Hi/Im8qrgFm7fkgrj AoCZeWMfhP/MMdJYdYF1Z9wNdKEKSLrjOu33xaw5e6N21fhSxXr4/PC23dRQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm3; t= 1739404624; x=1739491024; bh=DoyLnYvTZWNvZX7beByUBCgXSzqbcYSTSl6 eC9nKhn4=; b=fMzVw50AvpE+ElAirtbkAmVjMwrdqkpYRdf3Oks0nSYj3ynOgsC c0wABzmGswi35/am8rWTPZKMm9ksA15r0DQ/0+Eh/LdVfnYF9kzjkOe5+EXji6nj xYxR9qAGhoKDtMf8rnvlbHjYzYaovs5O0rUUB3j9V+ULn1/rSwrNZPQFWwIJeMwz dyqnbHn9gE3pCIxVg5MWxGN+Rdzr8Em5JkpHFBGqNnP1tjKCi8ZbnaKpLUmnxIhl +DhwXwAWdMY8AhwDbZMVnJTJpiTjQF3tbBd7m17H74F/CGqHktaB1Ww9GAw0Sl+F VmZBGUzytxUhIy3XhwA4pSKSt6PCMP2569A== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefvddrtddtgdeghedviecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpggftfghnshhusghstghrihgsvgdp uffrtefokffrpgfnqfghnecuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivg hnthhsucdlqddutddtmdenfghrlhcuvffnffculdejtddmnecujfgurhepfffhvfevuffk fhggtggujgesghdtreertddtvdenucfhrhhomhepofhitghhrggvlhcurfgrqhhuihgvrh cuoehmihgthhgrvghlsehprghquhhivghrrdighiiiqeenucggtffrrghtthgvrhhnpeet leeifedufffhhfdtteelgeeggeffhfekueevteeigfduudevudetgfegiedvjeenucevlh hushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpehmihgthhgrvghl sehprghquhhivghrrdighiiipdhnsggprhgtphhtthhopeehpdhmohguvgepshhmthhpoh huthdprhgtphhtthhopegrnhgurhgvshesrghnrghrrgiivghlrdguvgdprhgtphhtthho pehtghhlsehsshhsrdhpghhhrdhprgdruhhspdhrtghpthhtohepvghulhgvrhesvghulh gvrhhtohdrtghomhdprhgtphhtthhopehrrghnihgvrhdrvhhfsehgmhgrihhlrdgtohhm pdhrtghpthhtohepphhgshhqlhdqhhgrtghkvghrshesphhoshhtghhrvghsqhhlrdhorh hg X-ME-Proxy: Feedback-ID: i0fe9450f:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 12 Feb 2025 18:57:01 -0500 (EST) Date: Thu, 13 Feb 2025 08:56:53 +0900 From: Michael Paquier To: Andres Freund Cc: Tom Lane , Euler Taveira , "ranier.vf@gmail.com" , pgsql-hackers Subject: Re: Small memory fixes for pg_createsubcriber Message-ID: References: <68d6d810-4ef1-4f62-b47f-89b21501249b@app.fastmail.com> <3337507.1739376124@sss.pgh.pa.us> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="qjhby8jojjfBvt5H" Content-Disposition: inline In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --qjhby8jojjfBvt5H Content-Type: multipart/mixed; boundary="Yxgq/EINaf3jsJOi" Content-Disposition: inline --Yxgq/EINaf3jsJOi Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable 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. >=20 > 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 --Yxgq/EINaf3jsJOi Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="libpq-escape-fixes.patch" Content-Transfer-Encoding: quoted-printable diff --git a/src/bin/pg_amcheck/pg_amcheck.c b/src/bin/pg_amcheck/pg_amchec= k.c index 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[]) =20 executeCommand(conn, install_sql, opts.echo); pfree(install_sql); - pfree(schema); + PQfreemem(schema); } =20 /* diff --git a/src/bin/pg_upgrade/pg_upgrade.c b/src/bin/pg_upgrade/pg_upgrad= e.c index 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) =20 PQfreemem(datcollate_literal); PQfreemem(datctype_literal); - PQfreemem(datlocale_literal); + if (locale->db_locale) + PQfreemem(datlocale_literal); + else + pg_free(datlocale_literal); =20 PQfinish(conn_new_template1); =20 --Yxgq/EINaf3jsJOi-- --qjhby8jojjfBvt5H Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAABCgAdFiEEG72nH6vTowiyblFKnvQgOdbyQH0FAmetNUUACgkQnvQgOdby QH0VsBAAn7WfQHrFIiR+XCHFoXYhAKNMxKIbEmRrOZHUiFxAFSS96ilhK6l9rYzW BDOaYOxYMi+D+MDveehywl7igNHViH8fkWRefLFuqRkgFz6Lzr4RTtSFKmqx4qw1 ZoTkwOOmtpBMEf9ZrBp9wHUJ71+YRuOCQoc3Xw0p3XizOv50Br+cIlQWgd8L1+un QLCEb1/hKAxJx7S7BJFZV+JhqDs08fWzow3Jyazxt6J0IrgDV8mN/EWbuqmTy4Zl Mh71ERa+9kW9GtEky/3GtNrWGKVLpwpbKAjVezdGVEtUe05Kcv/SgL7/Mzmk2h2u yHOSBW3MqdkJIrtwq+CO9yjeBYKIChUmnCqL6kF1zIoniafQg1cnAYctHCM+5YY/ hn4OPBIciSLIlWsw8RBjtkI7LHd3WTyo8xS4tbqOm7IpT5Zj7dWKokGAtWN5LzKv 2pVRAxf9OWJL7bqeZiVKYBXuMGdYh+C2q2v22X06XeHxwbYInhifgZEgEop/GdYw mZT2bFWHvNLfaTQhE2Mtzf+FLZcLV/O085Oc644df5OVgB9iqjYXY7Vqa7pfaBbY F7nHMi47EuPpslWz3T8ZrMXIkeUA84igJ7qXPya9E1NyOTjUIl6hc9h8e3XKpce0 WQvDhTFVqhM2l4UOnUANFkS4HPGTHltFMdlV2DQ/bLq/3nwfCSo= =/T85 -----END PGP SIGNATURE----- --qjhby8jojjfBvt5H--