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 1tiMmV-00F64x-Ne for pgsql-hackers@arkaria.postgresql.org; Thu, 13 Feb 2025 00:08:39 +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 1tiMmT-00Gsw2-I4 for pgsql-hackers@arkaria.postgresql.org; Thu, 13 Feb 2025 00:08:38 +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 1tiMmT-00Gsve-8B for pgsql-hackers@lists.postgresql.org; Thu, 13 Feb 2025 00:08:37 +0000 Received: from sss.pgh.pa.us ([68.162.161.243]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1tiMmS-000UDp-0X for pgsql-hackers@postgresql.org; Thu, 13 Feb 2025 00:08:37 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 51D08VYh3490964; Wed, 12 Feb 2025 19:08:31 -0500 From: Tom Lane To: Michael Paquier cc: Andres Freund , Euler Taveira , "ranier.vf@gmail.com" , pgsql-hackers Subject: Re: Small memory fixes for pg_createsubcriber In-reply-to: References: <68d6d810-4ef1-4f62-b47f-89b21501249b@app.fastmail.com> <3337507.1739376124@sss.pgh.pa.us> Comments: In-reply-to Michael Paquier message dated "Thu, 13 Feb 2025 08:56:53 +0900" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <3490962.1739405311.1@sss.pgh.pa.us> Date: Wed, 12 Feb 2025 19:08:31 -0500 Message-ID: <3490963.1739405311@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Michael Paquier writes: > 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. Yeah, I suspected there would be places like that. It just hasn't mattered in practice up to now. (I have a vague recollection that Windows used to be pickier about this, but evidently not in recent years.) I spent a little time earlier today seeing what I could do with the use-dmalloc patch I posted earlier. It turns out you can get through initdb after s/free/PQfreemem/ in just two places, and then the backend works fine. But psql is a frickin' disaster --- there's free's of strings made with PQExpBuffer all over its backslash-command handling, and no easy way to clean it up. Maybe other clients will be less of a mess, but I'm not betting on that. regards, tom lane