Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1o7iFe-0002Q8-9p for pgsql-hackers@arkaria.postgresql.org; Sat, 02 Jul 2022 18:53:54 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1o7iFc-0001yC-Ow for pgsql-hackers@arkaria.postgresql.org; Sat, 02 Jul 2022 18:53:52 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1o7iFc-0001y3-Fu for pgsql-hackers@lists.postgresql.org; Sat, 02 Jul 2022 18:53:52 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1o7iFZ-0004Ww-KW for pgsql-hackers@postgresql.org; Sat, 02 Jul 2022 18:53:52 +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 262IrYjn964682; Sat, 2 Jul 2022 14:53:34 -0400 From: Tom Lane To: Noah Misch cc: Guillaume Lelarge , Benoit =?iso-8859-1?Q?Lobr=E9au?= , PostgreSQL Developers , "Dr. Michael Meskes" Subject: Re: Probable memory leak with ECPG and AIX In-reply-to: <20220418041645.GA1134228@rfd.leadboat.com> References: <20211212073411.GA2218865@rfd.leadboat.com> <20220101074055.GA54621@rfd.leadboat.com> <2865639.1641054902@sss.pgh.pa.us> <20220102000750.GB54621@rfd.leadboat.com> <20220418041645.GA1134228@rfd.leadboat.com> Comments: In-reply-to Noah Misch message dated "Sun, 17 Apr 2022 21:16:45 -0700" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <964680.1656788014.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Sat, 02 Jul 2022 14:53:34 -0400 Message-ID: <964681.1656788014@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Noah Misch writes: > I had expected to use pthread_once() for the newlocale() call, but there= would > be no useful way to report failure and try again later. Instead, I call= ed > newlocale() while ECPGconnect() holds connections_mutex. See log messag= e and > comments for details. I tested "./configure ac_cv_func_uselocale=3Dno .= .." and > tested the scenario of newlocale() failing every time. This looks solid to me. The only nit I can find to pick is that I'd have added one more comment, along the lines of diff --git a/src/interfaces/ecpg/ecpglib/connect.c b/src/interfaces/ecpg/e= cpglib/connect.c index 9f958b822c..96f99ae072 100644 --- a/src/interfaces/ecpg/ecpglib/connect.c +++ b/src/interfaces/ecpg/ecpglib/connect.c @@ -508,6 +508,11 @@ ECPGconnect(int lineno, int c, const char *name, cons= t char *user, const char *p #ifdef ENABLE_THREAD_SAFETY pthread_mutex_lock(&connections_mutex); #endif + + /* + * ... but first, make certain we have created ecpg_clocale. Rely on + * holding connections_mutex to ensure this is done by only one thread. + */ #ifdef HAVE_USELOCALE if (!ecpg_clocale) { I've marked it RFC. regards, tom lane