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 1o24Gg-0001T4-2S for pgsql-hackers@arkaria.postgresql.org; Fri, 17 Jun 2022 05:11:38 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1o24Ge-0001NU-UN for pgsql-hackers@arkaria.postgresql.org; Fri, 17 Jun 2022 05:11:36 +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 1o24Ge-0001NL-LZ for pgsql-hackers@lists.postgresql.org; Fri, 17 Jun 2022 05:11:36 +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 1o24Gc-0005XM-2L for pgsql-hackers@postgresql.org; Fri, 17 Jun 2022 05:11:36 +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 25H5BTTa1074831; Fri, 17 Jun 2022 01:11:29 -0400 From: Tom Lane To: Michael Paquier cc: Peter Eisentraut , pgsql-hackers Subject: Re: libpq: Remove redundant null pointer checks before free() In-reply-to: References: Comments: In-reply-to Michael Paquier message dated "Fri, 17 Jun 2022 12:25:07 +0900" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <1074829.1655442689.1@sss.pgh.pa.us> Date: Fri, 17 Jun 2022 01:11:29 -0400 Message-ID: <1074830.1655442689@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Michael Paquier writes: > On Thu, Jun 16, 2022 at 10:07:33PM +0200, Peter Eisentraut wrote: >> calls, where the "if" part is unnecessary. This is of course pretty >> harmless, but some functions like scram_free() and freePGconn() have become >> so bulky that it becomes annoying. So while I was doing some work in that >> area I undertook to simplify this. > Seems fine. Would some of the buildfarm dinosaurs hiccup on that? > gaur is one that comes into mind. Doubt it. (In any case, gaur/pademelon are unlikely to be seen again after a hardware failure --- I'm working on resurrecting that machine using modern NetBSD on an external drive, but its HPUX installation probably isn't coming back.) POSIX has required free(NULL) to be a no-op since at least SUSv2 (1997). Even back then, the machines that failed on it were legacy devices, like then-decade-old SunOS versions. So I don't think that Peter's proposal has any portability risk today. Having said that, the pattern "if (x) free(x);" is absolutely ubiquitous across our code, and so I'm not sure that I'm on board with undoing it only in libpq. I'd be happier if we made a push to get rid of it everywhere. Notably, I think the choice that pfree(NULL) is disallowed traces directly to worries about coding-pattern-compatibility with pre-POSIX free(). Should we revisit that? Independently of that concern, how much of a back-patch hazard might we create with such changes? regards, tom lane