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 1nHxPs-00042m-7D for pgsql-hackers@arkaria.postgresql.org; Thu, 10 Feb 2022 00:34:32 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1nHxPr-0000fD-3w for pgsql-hackers@arkaria.postgresql.org; Thu, 10 Feb 2022 00:34:31 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nHxPq-0000f4-R9 for pgsql-hackers@lists.postgresql.org; Thu, 10 Feb 2022 00:34:30 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nHxPo-00051s-La for pgsql-hackers@lists.postgresql.org; Thu, 10 Feb 2022 00:34:29 +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 21A0YRRv1524754; Wed, 9 Feb 2022 19:34:27 -0500 From: Tom Lane To: Peter Smith cc: PostgreSQL Hackers Subject: Re: GetRelationPublicationActions. - Remove unreachable code In-reply-to: References: Comments: In-reply-to Peter Smith message dated "Thu, 10 Feb 2022 11:23:26 +1100" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <1524752.1644453267.1@sss.pgh.pa.us> Date: Wed, 09 Feb 2022 19:34:27 -0500 Message-ID: <1524753.1644453267@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Peter Smith writes: > There appears to be some unreachable code in the relcache function > GetRelationPublicationActions. > When the 'relation->rd_pubactions' is not NULL then the function > unconditionally returns early (near the top). > Therefore, the following code (near the bottom) seems to have no > purpose because IIUC the 'rd_pubactions' can never be not NULL here. I'm not sure it's as unreachable as all that. What you're not accounting for is the possibility of recursive cache loading, ie something down inside the catalog fetches we have to do here could already have made the field valid. Admittedly, that's probably not very likely given expected usage patterns (to wit, that system catalogs shouldn't really have publication actions). But there are other places in relcache.c where a coding pattern similar to this is demonstrably necessary to avoid memory leakage. I'd rather leave the code as-is, maybe add a comment along the lines of "rd_pubactions is probably still NULL, but just in case something already made it valid, avoid leaking memory". regards, tom lane