Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1ZGaKD-0002gY-2c for pgsql-bugs@arkaria.postgresql.org; Sat, 18 Jul 2015 22:11:17 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84) (envelope-from ) id 1ZGaKC-00059p-K8 for pgsql-bugs@arkaria.postgresql.org; Sat, 18 Jul 2015 22:11:16 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84) (envelope-from ) id 1ZGaJY-00036S-DO for pgsql-bugs@postgresql.org; Sat, 18 Jul 2015 22:10:36 +0000 Received: from smtp-auth.no-ip.com ([8.23.224.61] helo=out.smtp-auth.no-ip.com) by magus.postgresql.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.84) (envelope-from ) id 1ZGaJT-0004Ae-M6 for pgsql-bugs@postgresql.org; Sat, 18 Jul 2015 22:10:35 +0000 X-No-IP: alvh.no-ip.org@noip-smtp X-Report-Spam-To: abuse@no-ip.com Received: from alvin.alvh.no-ip.org (unknown [195.39.71.250]) (Authenticated sender: alvh.no-ip.org@noip-smtp) by smtp-auth.no-ip.com (Postfix) with ESMTPA id 015AE400DD3; Sat, 18 Jul 2015 15:10:22 -0700 (PDT) Received: by alvin.alvh.no-ip.org (Postfix, from userid 1000) id AE8161B0B; Sat, 18 Jul 2015 19:54:21 +0400 (SAMT) Date: Sat, 18 Jul 2015 17:54:21 +0200 From: Alvaro Herrera To: Michael Paquier Cc: Tom Lane , Bill Parker , PostgreSQL mailing lists Subject: Re: Lack of Sanity Checking in file 'pctcl.c' for PostgreSQL 9.4.x Message-ID: <20150718155421.GZ2301@postgresql.org> References: <20150612194716.GQ133018@postgresql.org> <4457.1434166911@sss.pgh.pa.us> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: User-Agent: Mutt/1.5.23 (2014-03-12) X-Pg-Spam-Score: -0.3 (/) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-bugs Precedence: bulk Sender: pgsql-bugs-owner@postgresql.org Michael Paquier wrote: > On Sat, Jun 13, 2015 at 12:41 PM, Tom Lane wrote: > > Alvaro Herrera writes: > >> Michael Paquier wrote: > >>> By the way, your patch does not compile properly and is not in-line > >>> with the project's code format. See the updated patch attached ;) > > > >> ... or the conventions for allocating memory. Why not just use palloc()? > > > > That's hardly the fault of the proposed patch. But yeah, it seems like > > much the best fix here is to get rid of the malloc (and strdup) calls in > > this code in favor of using the palloc infrastructure. Even the calls > > that *do* have manual failure checks are not compliant with our usual > > coding standards. > > Hm. Regarding the code path mentioned by Bill something like the patch > attached is enough with a memory context for the query description. Right. Note this no longer needs the individual pfree() when aborting, because the MemoryContextDelete would remove the whole thing. (Don't bother resubmitting; I have already fixed it.) Will push shortly. > Now, perhaps we could do more efforts with prodesc as well, see for > example compile_pltcl_function for pltcl and similarly for plperl. > Thoughts? Right. It would simplify the code: create a memory context child of TopTransactionContext, then compile the function, and if successful, then MemoryContextSetParent to some longer-lived context. When the function is invalidated, it's sufficient to delete the context and create a new one. Creating the context as child of TopTransactionContext allows you to avoid an explicit MemoryContextDelete() in the elog(ERROR) cases while compiling. I do wonder how many users this code has ... -- Álvaro Herrera http://www.2ndQuadrant.com/ PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services -- Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs